org.springframework.richclient.components
Class ShuttleList

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 org.springframework.richclient.components.ShuttleList
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ShuttleList
extends JPanel

Custom panel that presents a "shuttle" list pair. One list is the "source" and the second list holds the "chosen" values from the source list. Buttons between the lists are used to move entries back and forth. By default, only the chosen list is displayed along with an Edit button. Pressing the edit button exposes the source list and the movement buttons.

This component essentially provides an alternate UI for a JList. It uses the same type of model and selection list. The selection is rendered as two lists instead of one list with highlighted entries. Those elements in the model that are not selected are shown in the source list and those that are selected are shown in the chosen list.

Normal selection model listeners are used to report changes to interested objects.

Author:
lstreepy, Benoit Xhenseval (Small modifications for text + icons config), Geoffrey De Smet
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
 
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
ShuttleList()
          Simple constructor.
ShuttleList(boolean showEditButton)
           
 
Method Summary
 void addListSelectionListener(ListSelectionListener listener)
          Adds a listener to the list that's notified each time a change to the selection occurs.
protected  JPanel buildButtonPanel()
          Construct the control button panel.
protected  JComponent buildComponent()
          Build our component panel.
 void clearSelection()
          Clear the selection.
 ListCellRenderer getCellRenderer()
          Returns the object that renders the list items.
 ListModel getModel()
          Returns the data model.
 Object[] getSelectedValues()
          Returns an array of the values for the selected cells.
 ListSelectionModel getSelectionModel()
          Returns the value of the current selection model.
protected  int indexOf(Object o)
          Get the index of a given object in the underlying data model.
protected  void moveAllLeftToRight()
          Move all the source items to the chosen side.
protected  void moveAllRightToLeft()
          Move all the chosen items back to the source side.
protected  void moveLeftToRight()
          Move the selected items in the source list to the chosen list.
protected  void moveRightToLeft()
          Move the selected items in the chosen list to the source list.
 void removeListSelectionListener(ListSelectionListener listener)
          Removes a listener from the list that's notified each time a change to the selection occurs.
 void setCellRenderer(ListCellRenderer cellRenderer)
          Sets the delegate that's used to paint each cell in the list.
 void setComparator(Comparator comparator)
          Set the comparator to use for comparing list elements.
 void setEditIcon(Icon editIcon, String text)
          Set the icon to use on the edit button.
 void setEnabled(boolean enabled)
           
 void setListLabels(String chosenLabel, String sourceLabel)
          Add labels on top of the 2 lists.
 void setModel(ListModel model)
          Sets the model that represents the contents or "value" of the list and clears the list selection.
 void setSelectedIndices(int[] indices)
          Selects a set of cells.
 void setVisibleRowCount(int visibleRowCount)
          Sets the preferred number of rows in the list that can be displayed without a scrollbar.
 void togglePanels()
          Toggle the panel visibility.
protected  void update()
          Update the two lists based on the current selection indices.
 
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, 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, 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
 
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
 

Constructor Detail

ShuttleList

public ShuttleList()
Simple constructor.


ShuttleList

public ShuttleList(boolean showEditButton)
Method Detail

getCellRenderer

public ListCellRenderer getCellRenderer()
Returns the object that renders the list items.

Returns:
the ListCellRenderer
See Also:
setCellRenderer(javax.swing.ListCellRenderer)

setCellRenderer

public void setCellRenderer(ListCellRenderer cellRenderer)
Sets the delegate that's used to paint each cell in the list.

The default value of this property is provided by the ListUI delegate, i.e. by the look and feel implementation.

Parameters:
cellRenderer - the ListCellRenderer that paints list cells
See Also:
getCellRenderer()

getModel

public ListModel getModel()
Returns the data model.

Returns:
the ListModel that provides the displayed list of items

setModel

public void setModel(ListModel model)
Sets the model that represents the contents or "value" of the list and clears the list selection.

Parameters:
model - the ListModel that provides the list of items for display
Throws:
IllegalArgumentException - if model is null

setVisibleRowCount

public void setVisibleRowCount(int visibleRowCount)
Sets the preferred number of rows in the list that can be displayed without a scrollbar.

Parameters:
visibleRowCount - an integer specifying the preferred number of visible rows

setComparator

public void setComparator(Comparator comparator)
Set the comparator to use for comparing list elements.

Parameters:
comparator - to use

setEditIcon

public void setEditIcon(Icon editIcon,
                        String text)
Set the icon to use on the edit button. If no icon is specified, then just the label will be used otherwise the text will be a tooltip.

Parameters:
editIcon - Icon to use on edit button

setListLabels

public void setListLabels(String chosenLabel,
                          String sourceLabel)
Add labels on top of the 2 lists. If not present, do not show the labels.

Parameters:
chosenLabel -
sourceLabel -

buildComponent

protected JComponent buildComponent()
Build our component panel.

Returns:
component

buildButtonPanel

protected JPanel buildButtonPanel()
Construct the control button panel.

Returns:
JPanel

togglePanels

public void togglePanels()
Toggle the panel visibility. This will hide/show the source list and movement buttons.


moveLeftToRight

protected void moveLeftToRight()
Move the selected items in the source list to the chosen list. I.e., add the items to our selection model.


moveAllLeftToRight

protected void moveAllLeftToRight()
Move all the source items to the chosen side. I.e., select all the items.


moveRightToLeft

protected void moveRightToLeft()
Move the selected items in the chosen list to the source list. I.e., remove them from our selection model.


moveAllRightToLeft

protected void moveAllRightToLeft()
Move all the chosen items back to the source side. This simply sets our selection back to empty.


indexOf

protected int indexOf(Object o)
Get the index of a given object in the underlying data model.

Parameters:
o - Object to locate
Returns:
index of object in model, -1 if not found

update

protected void update()
Update the two lists based on the current selection indices.


getSelectionModel

public ListSelectionModel getSelectionModel()
Returns the value of the current selection model.

Returns:
the ListSelectionModel that implements list selections

addListSelectionListener

public void addListSelectionListener(ListSelectionListener listener)
Adds a listener to the list that's notified each time a change to the selection occurs.

Parameters:
listener - the ListSelectionListener to add

removeListSelectionListener

public void removeListSelectionListener(ListSelectionListener listener)
Removes a listener from the list that's notified each time a change to the selection occurs.

Parameters:
listener - the ListSelectionListener to remove

clearSelection

public void clearSelection()
Clear the selection. This will populate the source list with all the items from the model and empty the chosen list.


setSelectedIndices

public void setSelectedIndices(int[] indices)
Selects a set of cells.

Parameters:
indices - an array of the indices of the cells to select

getSelectedValues

public Object[] getSelectedValues()
Returns an array of the values for the selected cells. The returned values are sorted in increasing index order.

Returns:
the selected values or an empty list if nothing is selected

setEnabled

public void setEnabled(boolean enabled)
Overrides:
setEnabled in class JComponent


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.