Holger's Java API

## com.antelmann.util.gui
Class JPropertyEntryComponent

    java.lang.Object
      java.awt.Component
          java.awt.Container
              javax.swing.JComponent
                  com.antelmann.util.gui.JPropertyEntryComponent

All Implemented Interfaces:
  EditableComponent, ValueRetriever<PropertyEntry>, ImageObserver, MenuContainer, Serializable

Direct Known Subclasses:
  JPropertyEntryForm

    public class JPropertyEntryComponent

extends JComponent
implements EditableComponent, ValueRetriever<PropertyEntry>

implements a general component for editing `PropertyEntry` objects. Since `validateForm(Component)` is already implemented, it should be very easy to create an inheriting class implementing `FormValidator` by simply providing `FormValidator.commitFormAction(Component)`.

Since:
  25.09.2008, 20:37:31
Author:
  Holger Antelmann
See Also:
  `JMethodTableModelComponent`, Serialized Form

Nested Class Summary

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 PropertyEntry` `entry`
`protected Hashtable<String,JComponent>` `keyFields`

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
`JPropertyEntryComponent(PropertyEntry entry, int padding, int maxRows, boolean initComponent, FormHelper formHelper, String... propertyKeys)`
`JPropertyEntryComponent(PropertyEntry entry, int padding, int maxRows, boolean initComponent, String... propertyKeys)`
`JPropertyEntryComponent(PropertyEntry entry, int padding, int maxRows, String... propertyKeys)`
`JPropertyEntryComponent(PropertyEntry entry, String... propertyKeys)`
`JPropertyEntryComponent(RowItem ri)`

Method Summary
`void` `applyFormToEntry()` sets all properties from this form based on the values provided by `getValue(JComponent)`
`protected void` `applyValueToForm(Object value, JComponent keyField)` applies the given value to the given component.
`protected JComponent` `createComponentFor(Class<?> c)` This implementation supports String (via JTextField), Number (via JFormattedTextField), Boolean (via JCheckBox), Color (via JColorChooser) and Date (via JTimeChooser); others are simply handled via JTextField (including a null parameter).
`protected JComponent` `createComponentFor(String key)` returns the editor component for the given property key; if the key is not to be edited, null is to be returned.
`protected JComponent` `createLabelFor(String key)` allows to customize the way the labels for each key are created
`protected Class<?>` `getClassFor(String key)` this implementation returns the property value of the given key from the embedded entry; null is returned if the value from this entry instance is null.
`PropertyEntry` `getRelevantValue()` returns the relevant value for this instance at the time of calling
`protected Object` `getValue(JComponent keyField)` allows to specialize the way how the value for the given key is retrieved from the given component.
`protected void` `initComponent(int padding, int maxRows, String[] propertyKeys)` called by the constructor already only if initComponent parameter was set to true
`protected void` `initListener(JComponent keyField)` this method is called by `createComponentFor(String)` to fire a property change event upon field alterations with the key `Form.EDIT_PROPERTY_KEY` on this instance.
`boolean` `isEditable()`
`void` `setEditable(boolean flag)`
`void` `setEnabled(boolean flag)`
`void` `setEntry(PropertyEntry entry)`
`void` `validateForm(Component formComponent)` this convenience method makes it simpler to implement a `FormValidator` based on this class.

Methods inherited from class javax.swing.JComponent

`addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI`

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`

Field Detail

### entry

    protected PropertyEntry entry

### keyFields

    protected final Hashtable<String,JComponent> keyFields

Constructor Detail

### JPropertyEntryComponent

    public JPropertyEntryComponent(RowItem ri)

### JPropertyEntryComponent

    public JPropertyEntryComponent(PropertyEntry entry,
                                   String... propertyKeys)
                            throws IllegalArgumentException

Throws:
  `IllegalArgumentException`

### JPropertyEntryComponent

    public JPropertyEntryComponent(PropertyEntry entry,
                                   int padding,
                                   int maxRows,
                                   String... propertyKeys)
                            throws IllegalArgumentException

Throws:
  `IllegalArgumentException`

### JPropertyEntryComponent

    public JPropertyEntryComponent(PropertyEntry entry,
                                   int padding,
                                   int maxRows,
                                   boolean initComponent,
                                   String... propertyKeys)
                            throws IllegalArgumentException

Throws:
  `IllegalArgumentException`

### JPropertyEntryComponent

    public JPropertyEntryComponent(PropertyEntry entry,
                                   int padding,
                                   int maxRows,
                                   boolean initComponent,
                                   FormHelper formHelper,
                                   String... propertyKeys)
                            throws IllegalArgumentException

Throws:
  `IllegalArgumentException`

Method Detail

### initComponent

    protected void initComponent(int padding,
                                 int maxRows,
                                 String[] propertyKeys)

  called by the constructor already only if initComponent parameter was set to true

### getRelevantValue

    public PropertyEntry getRelevantValue()
                                   throws IOException

  Description copied from interface: `ValueRetriever`
  returns the relevant value for this instance at the time of calling

  Specified by:
    `getRelevantValue` in interface `ValueRetriever<PropertyEntry>`
  Throws:
    `IOException` - if any resource to fulfill the request is not accessible

### createComponentFor

    protected JComponent createComponentFor(String key)

  returns the editor component for the given property key; if the key is not to be edited, null is to be returned. This implementation creates a component based on `getClassFor(String)`; also, this implementation calls `initListener(JComponent)` on the returned component. If certain keys are to be handled more specifically (like using a JSpinner, JComboBox, etc.), this method should be overwritten accordingly.

  See Also:
    `initListener(JComponent)`

### initListener

    protected void initListener(JComponent keyField)

  this method is called by `createComponentFor(String)` to fire a property change event upon field alterations with the key `Form.EDIT_PROPERTY_KEY` on this instance. This implementation supports the same components as `getValue(JComponent)`.

### setEnabled

    public void setEnabled(boolean flag)

  Overrides:
    `setEnabled` in class `JComponent`

### isEditable

    public boolean isEditable()

  Specified by:
    `isEditable` in interface `EditableComponent`

### setEditable

    public void setEditable(boolean flag)

  Specified by:
    `setEditable` in interface `EditableComponent`

### applyValueToForm

    protected void applyValueToForm(Object value,
                                    JComponent keyField)
                             throws IllegalArgumentException,
                                    ClassCastException

  applies the given value to the given component. This implementation supports the same components as `getValue(JComponent)`

  Throws:
    `IllegalArgumentException`
    `ClassCastException`

### getValue

    protected Object getValue(JComponent keyField)
                       throws IllegalArgumentException

  allows to specialize the way how the value for the given key is retrieved from the given component. This implementation ignores the key parameter and just retrieves the value from the supported components.

  Throws:
    `IllegalArgumentException` - if the given keyField is not supported
  See Also:
    `JCheckBox`, `JComboBox`, `JSpinner`, `JFormattedTextField`, `JTextComponent`, `JSlider`, `JColorChooser`

### applyFormToEntry

    public void applyFormToEntry()
                          throws IllegalArgumentException

  sets all properties from this form based on the values provided by `getValue(JComponent)`

  Throws:
    `IllegalArgumentException`

### getClassFor

    protected Class<?> getClassFor(String key)

  this implementation returns the property value of the given key from the embedded entry; null is returned if the value from this entry instance is null.

### createComponentFor

    @Warning(value="called by the constructor if initComponent was set to true")
    protected JComponent createComponentFor(Class<?> c)

  This implementation supports String (via JTextField), Number (via JFormattedTextField), Boolean (via JCheckBox), Color (via JColorChooser) and Date (via JTimeChooser); others are simply handled via JTextField (including a null parameter). This method is called by `createComponentFor(String)`.

### createLabelFor

    @Warning(value="called by the constructor if initComponent was set to true")
    protected JComponent createLabelFor(String key)

  allows to customize the way the labels for each key are created

### setEntry

    public void setEntry(PropertyEntry entry)

### validateForm

    public void validateForm(Component formComponent)
                      throws FormValidationWarning,
                             IllegalArgumentException

  this convenience method makes it simpler to implement a `FormValidator` based on this class. This implementation applies all field values to the embedded entry and throws an appropriate `FormValidationWarning` if that fails.

  Throws:
    `FormValidationWarning`
    `IllegalArgumentException`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads