Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.jgoodies.validation.tutorial.util
Class IconFeedbackPanel  view IconFeedbackPanel download IconFeedbackPanel.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JLayeredPane
                  extended bycom.jgoodies.validation.tutorial.util.IconFeedbackPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public final class IconFeedbackPanel
extends javax.swing.JLayeredPane

Can display validation feedback icons "over" a content panel. It observes a ValidationResultModel and creates icon labels in a feedback layer of a javax.swing.JLayeredPane on top of the content layer. To position the feedback labels, the content pane is traversed and searched for text components that match a validation message key in this panel's observed ValidationResultModel.

This panel handles two event types:

  1. the ValidationResultModel changes,
  2. the content layout changes.

TODO: Check how the wrapping mechanism shall work with JSplitPanes, JTabbedPanes and CardPanels. At least provide guidelines, how to wrap these panel types, or how to handle these cases.

TODO: Turn this class into an abstract superclass. Subclasses shall implement the feedback component creation and specify where to locate the feedback component relative to the underlying content component.

TODO: Consider adding a mechanism, so that components can be added and removed later.

Version:
$Revision: 1.4 $

Nested Class Summary
private  class IconFeedbackPanel.SimpleLayout
           
private  class IconFeedbackPanel.ValidationResultChangeHandler
           
 
Nested classes inherited from class javax.swing.JLayeredPane
javax.swing.JLayeredPane.AccessibleJLayeredPane
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  javax.swing.JComponent content
          Refers to the content panel that holds the content components.
private static int CONTENT_LAYER
           
private static int FEEDBACK_LAYER
           
private  ValidationResultModel model
          Holds the ValidationResult and reports changes in that result.
 
Fields inherited from class javax.swing.JLayeredPane
DEFAULT_LAYER, DRAG_LAYER, FRAME_CONTENT_LAYER, LAYER_PROPERTY, MODAL_LAYER, PALETTE_LAYER, POPUP_LAYER
 
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.Container
 
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
IconFeedbackPanel(ValidationResultModel model, javax.swing.JComponent content)
          Creates an IconFeedbackPanel on the given ValidationResultModel using the specified content panel.
 
Method Summary
private  void addFeedbackComponent(java.awt.Component contentComponent, javax.swing.JComponent messageComponent, java.util.Map keyMap, int xOffset, int yOffset)
           
private  javax.swing.JComponent createFeedbackComponent(ValidationResult result, java.awt.Component contentComponent)
          Creates and returns a validation feedback component that shall overlay the specified content component.
private static ValidationResult getAssociatedResult(javax.swing.JComponent comp, java.util.Map keyMap)
          Returns the ValidationResult associated with the given component using the specified validation result key map.
private  java.awt.Point getFeedbackComponentOrigin(javax.swing.JComponent feedbackComponent, java.awt.Component contentComponent)
          Computes and returns the origin of the given feedback component using the content component's origin.
static javax.swing.JComponent getWrappedComponentTree(ValidationResultModel model, javax.swing.JComponent root)
          Wraps the components in the given component tree with instances of IconFeedbackPanel where necessary.
private  void initEventHandling()
          Registers a listener with the validation result model that updates the feedback components.
 void invalidate()
          TODO: Check how to handle layout changes properly.
private static boolean isMarkable(java.awt.Component component)
          Checks and answers if the given component can be marked or not.
private static boolean isScrollPaneView(java.awt.Component c)
           
private static boolean isScrollPaneWithUnmarkableView(java.awt.Component c)
           
private  void removeAllFeedbackComponents()
           
private  void repositionFeedbackComponents()
          TODO: Improve this implementation to set only positions.
private  void updateFeedbackComponents()
           
private  void visitComponentTree(java.awt.Container container, java.util.Map keyMap, int xOffset, int yOffset)
          Traverses the component tree starting at the given container and creates a feedback component for each JTextComponent that is associated with a message in the specified keyMap.
private static void wrapComponentTree(ValidationResultModel model, java.awt.Container container)
           
 
Methods inherited from class javax.swing.JLayeredPane
addImpl, getAccessibleContext, getComponentCountInLayer, getComponentsInLayer, getComponentToLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, putLayer, remove, removeAll, setLayer, setLayer, setPosition
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, 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, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, 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, processMouseEvent, 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, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONTENT_LAYER

private static final int CONTENT_LAYER
See Also:
Constant Field Values

FEEDBACK_LAYER

private static final int FEEDBACK_LAYER
See Also:
Constant Field Values

model

private final ValidationResultModel model
Holds the ValidationResult and reports changes in that result. Used to update the state of the feedback components.


content

private final javax.swing.JComponent content
Refers to the content panel that holds the content components.

Constructor Detail

IconFeedbackPanel

public IconFeedbackPanel(ValidationResultModel model,
                         javax.swing.JComponent content)
Creates an IconFeedbackPanel on the given ValidationResultModel using the specified content panel.

Note: Typically you should wrap component trees with getWrappedComponentTree(ValidationResultModel, JComponent) 55 , not this constructor.

Note: You must not add or remove components from the content once this constructor has been invoked.

Method Detail

getWrappedComponentTree

public static javax.swing.JComponent getWrappedComponentTree(ValidationResultModel model,
                                                             javax.swing.JComponent root)
Wraps the components in the given component tree with instances of IconFeedbackPanel where necessary. Such a wrapper is required for all JScrollPanes that contain multiple children and for the root - unless it's a JScrollPane with multiple children.


wrapComponentTree

private static void wrapComponentTree(ValidationResultModel model,
                                      java.awt.Container container)

isScrollPaneWithUnmarkableView

private static boolean isScrollPaneWithUnmarkableView(java.awt.Component c)

initEventHandling

private void initEventHandling()
Registers a listener with the validation result model that updates the feedback components.


createFeedbackComponent

private javax.swing.JComponent createFeedbackComponent(ValidationResult result,
                                                       java.awt.Component contentComponent)
Creates and returns a validation feedback component that shall overlay the specified content component.

This implementation returns a JLabel. The validation result's severity is used to lookup the label's icon; the result's message text is set as the label's tooltip text.

TODO: Turn this method into an abstract method if this class becomes an abstract superclass of general feedback overlay panels.


getFeedbackComponentOrigin

private java.awt.Point getFeedbackComponentOrigin(javax.swing.JComponent feedbackComponent,
                                                  java.awt.Component contentComponent)
Computes and returns the origin of the given feedback component using the content component's origin.

This implementation returns a JLabel. The validation result's severity is used to lookup the label's icon; the result's message text is set as the label's tooltip text.

TODO: Turn this method into an abstract method if this class becomes an abstract superclass of general feedback overlay panels.


removeAllFeedbackComponents

private void removeAllFeedbackComponents()

visitComponentTree

private void visitComponentTree(java.awt.Container container,
                                java.util.Map keyMap,
                                int xOffset,
                                int yOffset)
Traverses the component tree starting at the given container and creates a feedback component for each JTextComponent that is associated with a message in the specified keyMap.

The arguments passed to the feedback component creation method are the visited component and its associated validation subresult. This subresult is requested from the specified keyMap using the visited component's message key.


isScrollPaneView

private static boolean isScrollPaneView(java.awt.Component c)

isMarkable

private static boolean isMarkable(java.awt.Component component)
Checks and answers if the given component can be marked or not.

TODO: Check the combobox editable state.

TODO: Add the JSpinner to the list of markable components.


addFeedbackComponent

private void addFeedbackComponent(java.awt.Component contentComponent,
                                  javax.swing.JComponent messageComponent,
                                  java.util.Map keyMap,
                                  int xOffset,
                                  int yOffset)

getAssociatedResult

private static ValidationResult getAssociatedResult(javax.swing.JComponent comp,
                                                    java.util.Map keyMap)
Returns the ValidationResult associated with the given component using the specified validation result key map.


updateFeedbackComponents

private void updateFeedbackComponents()

repositionFeedbackComponents

private void repositionFeedbackComponents()
TODO: Improve this implementation to set only positions. The current implementation removes all components and re-adds them later.


invalidate

public void invalidate()
TODO: Check how to handle layout changes properly.