public class DualList extends JideSplitPane
DualList
is a pane that contains two JLists and a bunch of buttons. The list on the left contains all
the items. The list on the right contains the items that are selected.
DualList
uses DualListModel
which is the model of this component. With the help of
DualListModel, it provides three kinds of selection modes. This mode controls what to display in the right list when
items are selected. DualListModel.REMOVE_SELECTION
mode means the left list will remove the items if they are
selected to the right list. This mode can prevent user from selecting the selected item again if it is not allowed in
certain cases. DualListModel.DISABLE_SELECTION
mode means the selected items will be shown as disabled. User
cannot select them anymore but they can still see them in the right list to show user a complete unchanged list.
DualListModel.KEEP_SELECTION
mode will not change the right list at all when items are selected. This is the
only mode which can result duplicated items to be selected. If that's what you want in your situation, this mode is
the one you should use. You could disable the duplicate selection option by invoking {link #setAllowDuplicates(false)}.
DualList
extends JideSplitPane
, which makes users conveniently resize the width of either list.
JideSplitPane.AccessibleJideSplitPane
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected DualListModel |
_model |
protected DefaultListModelWrapper |
_originalListModel |
JComponent |
_originalListPane |
protected DefaultListModelWrapper |
_selectedListModel |
JComponent |
_selectedListPane |
String |
CLIENT_PROPERTY_ALWAYS_DISABLED |
static String |
COMMAND_MOVE_ALL_LEFT |
static String |
COMMAND_MOVE_ALL_RIGHT |
static String |
COMMAND_MOVE_DOWN |
static String |
COMMAND_MOVE_LEFT |
static String |
COMMAND_MOVE_RIGHT |
static String |
COMMAND_MOVE_TO_BOTTOM |
static String |
COMMAND_MOVE_TO_TOP |
static String |
COMMAND_MOVE_UP |
_windowDeactivatedListener, CONTINUOUS_LAYOUT_PROPERTY, DIVIDER_SIZE_PROPERTY, GRIPPER_PROPERTY, HORIZONTAL_SPLIT, NON_CONTINUOUS_DIVIDER, ONE_TOUCH_EXPANDABLE_PROPERTY, ORIENTATION_PROPERTY, PROPERTY_DIVIDER_LOCATION, PROPERTY_HEAVYWEIGHT_COMPONENT_ENABLED, PROPORTIONAL_LAYOUT_PROPERTY, PROPORTIONS_PROPERTY, VERTICAL_SPLIT
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
DualList()
Constructs a
JList with an empty _model. |
DualList(DualListModel model)
Constructs a
DualList that displays the elements in the specified, non-null model. |
DualList(List<?> listData)
Constructs a
DualList that displays the elements in the specified List . |
DualList(Object[] listData)
Constructs a
JList that displays the elements in the specified array. |
Modifier and Type | Method and Description |
---|---|
protected void |
addButtonPanel(Container container,
Component buttonPanel)
Adds ButtonPanel to DualList.
|
void |
addSelectionInteval(int index0,
int index1)
Change the selection to be the set union of the current selection and the indices between index0 and index1
inclusive.
|
void |
clearSelection()
Removes all the selections.
|
protected AbstractButton |
createButton(Action action)
Creates the button.
|
protected Container |
createButtonPanel() |
protected JList |
createList(ListModel model,
boolean originalList)
Creates the JList.
|
ListCellRenderer |
getCellRenderer()
Gets the list cell renderer for the left list.
|
ListCellRenderer |
getDisabledCellRenderer()
Returns the disabled cell renderer.
|
protected ImageIcon |
getImageIcon(String url)
Subclass can override this method to provide the imageIcon.
|
DualListModel |
getModel()
Gets the DualListModel.
|
JList |
getOriginalList()
Get the original JList.
|
JComponent |
getOriginalListPane()
Gets the component containing the original JList.
|
Dimension |
getPreferredSize() |
protected String |
getResourceString(String key)
Gets the localized string from resource bundle.
|
ListCellRenderer |
getSelectedCellRenderer()
Gets the list cell renderer for the right list.
|
int[] |
getSelectedIndices()
Gets the selected indices.
|
JList |
getSelectedList()
Get the selected JList.
|
JComponent |
getSelectedListPane()
Gets the component containing the selected JList.
|
Object[] |
getSelectedValues()
Gets the selected values from the DualList.
|
int |
getSelectionMode()
Gets the selection mode from DualListModel.
|
int[] |
getUnselectedIndices() |
Object[] |
getUnselectedValues()
Returns the values that are not selected in
DaulList |
int |
getVisibleRowCount()
Returns the value of the
visibleRowCount from the list. |
protected void |
installKeyboardAction()
Registered keyboard actions for the original and selected lists.
|
boolean |
isAllowDuplicates()
Get the flag if duplicate selection is allowed in the DualList.
|
boolean |
isButtonEnabled(String command)
Checks if the button is always disabled.
|
boolean |
isButtonPanelVisible()
Deprecated.
Replaced by
isMiddleButtonPanelVisible() |
boolean |
isButtonVisible(String command)
Checks if the button is visible.
|
boolean |
isDoubleClickEnabled()
Gets the flag indicating if double click to select is enabled.
|
boolean |
isMiddleButtonPanelVisible()
Get the visibility of the middle button panel.
|
boolean |
isRightButtonPanelVisible()
Get the visibility of the right button panel.
|
boolean |
isSelectedIndex(int index)
Checks if the index is selected.
|
boolean |
isSelectionEmpty()
Checks if there is any selection.
|
void |
moveAllLeft()
Moves all items from the right list to the left list.
|
void |
moveAllRight()
Moves all items from the left list to the right list.
|
void |
moveDown()
Moves the selected items in the right list down by one.
|
void |
moveLeft()
Moves the selected items in the right list to the left list.
|
void |
moveRight()
Moves the selected items in the left list to the right list.
|
void |
moveToBottom()
Moves the selected items in the right list to the bottom.
|
void |
moveToTop()
Moves the selected items in the right list to the top.
|
void |
moveUp()
Moves the selected items in the right list up by one.
|
protected void |
performAction(String command)
Performs the action.
|
void |
removeSelectionInteval(int index0,
int index1)
Change the selection to be the set difference of the current selection and the indices between index0 and index1
inclusive.
|
void |
setAllowDuplicates(boolean allowDuplicates)
Set the flag if duplicate selection is allowed in the DualList.
|
void |
setButtonEnabled(String command,
boolean enabled)
Sets the button to always disabled.
|
void |
setButtonPanelVisible(boolean buttonPanelVisible)
Deprecated.
Replaced by
setMiddleButtonPanelVisible(boolean) |
void |
setButtonVisible(String command,
boolean visible)
Sets the button visible or invisible.
|
void |
setCellRenderer(ListCellRenderer cellRenderer)
Sets the list cell renderer for the list on the left.
|
void |
setDisabledCellRenderer(ListCellRenderer disabledCellRenderer)
Sets the disabled cell renderer.
|
void |
setDoubleClickEnabled(boolean doubleClickEnabled)
Sets the flag indicating if double click to select is enabled.
|
void |
setEnabled(boolean enabled) |
void |
setMiddleButtonPanelVisible(boolean middleButtonPanelVisible)
Set the visibility of the middle button panel.
|
void |
setModel(DualListModel model)
Sets the DualListModel.
|
void |
setRightButtonPanelVisible(boolean middleButtonPanelVisible)
Set the visibility of the right button panel.
|
void |
setSelectedCellRenderer(ListCellRenderer selectedCellRenderer)
Sets the list cell renderer for the list on the right.
|
void |
setSelectionMode(int selectionMode)
Sets the selection mode to
DualListModel . |
protected void |
setupList(JList list,
boolean originalList)
Customizes the JList.
|
void |
setVisibleRowCount(int visibleRowCount)
Sets the visible row count in the two lists.
|
addExtraDividers, addPane, addProportion, componentAdded, componentHidden, componentMoved, componentRemoved, componentResized, componentShown, createSplitPaneDivider, doLayout, dragDividerTo, finishDraggingTo, getAccessibleContext, getDividerAt, getDividerLocation, getDividerLocations, getDividerSize, getDividerStepSize, getLeftOneTouchButtonImageIcon, getNextDividerLocation, getOrientation, getPaneAt, getPaneCount, getPreviousDividerLocation, getProportions, getRightOneTouchButtonImageIcon, indexOf, indexOfDivider, indexOfPane, insertPane, insertPane, isContinuousLayout, isDragResizable, isHeavyweightComponentEnabled, isInitiallyEven, isOneTouchExpandable, isProportionalLayout, isShowGripper, isValidateRoot, removeExtraDividers, removePane, removePane, removeProportion, resetToPreferredSizes, setContinuousLayout, setDividerLocation, setDividerLocation, setDividerLocations, setDividerSize, setDividerStepSize, setDividersVisible, setDragResizable, setHeavyweightComponentEnabled, setInitiallyEven, setLeftOneTouchButtonImageIcon, setOneTouchExpandable, setOrientation, setPaneAt, setPaneAt, setProportionalLayout, setProportions, setRightOneTouchButtonImageIcon, setShowGripper, setVisible, startDragging, updateUI
getUI, getUIClassID, paramString, setUI
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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, 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, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, 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, transferFocusDownCycle, validate, validateTree
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, 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, transferFocusBackward, transferFocusUpCycle
public static final String COMMAND_MOVE_LEFT
public static final String COMMAND_MOVE_RIGHT
public static final String COMMAND_MOVE_ALL_LEFT
public static final String COMMAND_MOVE_ALL_RIGHT
public static final String COMMAND_MOVE_UP
public static final String COMMAND_MOVE_DOWN
public static final String COMMAND_MOVE_TO_TOP
public static final String COMMAND_MOVE_TO_BOTTOM
protected DualListModel _model
public JComponent _originalListPane
public JComponent _selectedListPane
public final String CLIENT_PROPERTY_ALWAYS_DISABLED
protected DefaultListModelWrapper _selectedListModel
protected DefaultListModelWrapper _originalListModel
public DualList()
JList
with an empty _model.public DualList(Object[] listData)
JList
that displays the elements in the specified array. This constructor just
delegates to the DualListModel
constructor.listData
- the array of Objects to be loaded into the data _modelpublic DualList(List<?> listData)
DualList
that displays the elements in the specified List
. This
constructor just delegates to the DualListModel
constructor.listData
- the List
to be loaded into the data _modelpublic DualList(DualListModel model)
DualList
that displays the elements in the specified, non-null
model. All
DualList
constructors delegate to this one.model
- the data model for this listNullPointerException
- if model
is null
protected JList createList(ListModel model, boolean originalList)
model
- the list modeloriginalList
- true if the JList is for the original list. False if the JList is for the selected list.protected void setupList(JList list, boolean originalList)
list
- the JList. It could be either the original JList or the selected JList.originalList
- true if the JList is for the original list. False if the JList is for the selected list.public JList getOriginalList()
public JList getSelectedList()
public JComponent getOriginalListPane()
public JComponent getSelectedListPane()
protected void addButtonPanel(Container container, Component buttonPanel)
container
- the container between the two JLists.buttonPanel
- the button panelpublic Dimension getPreferredSize()
getPreferredSize
in class JComponent
protected Container createButtonPanel()
protected ImageIcon getImageIcon(String url)
url
- url to the iconprotected AbstractButton createButton(Action action)
protected AbstractButton createButton(Action action) {
AbstractButton button = new JideButton(action);
action.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if ("disabledIcon".equals(evt.getPropertyName())) {
button.setDisabledIcon((Icon) action.getValue("disabledIcon"));
}
}
});
button.setName("" + action.getValue(Action.ACTION_COMMAND_KEY));
button.setDisabledIcon((Icon) action.getValue("disabledIcon"));
button.setRequestFocusEnabled(false);
return button;
}
action
- the action for the button.public void setEnabled(boolean enabled)
setEnabled
in class JComponent
public int[] getSelectedIndices()
DualListModel.getSelectedIndices()
public int[] getUnselectedIndices()
protected void installKeyboardAction()
public DualListModel getModel()
public void setModel(DualListModel model)
model
- a new DualListModel.public Object[] getSelectedValues()
public Object[] getUnselectedValues()
DaulList
public boolean isSelectedIndex(int index)
index
- the index.public void clearSelection()
public void addSelectionInteval(int index0, int index1)
index0
- one end of the interval.index1
- other end of the intervalpublic void removeSelectionInteval(int index0, int index1)
index0
- one end of the interval.index1
- other end of the intervalpublic boolean isSelectionEmpty()
public int getSelectionMode()
DualListModel.getSelectionMode()
public void setSelectionMode(int selectionMode)
DualListModel
.selectionMode
- the new selection mode.DualListModel.setSelectionMode(int)
public void setButtonVisible(String command, boolean visible)
command
- the name defined in DualList. They are constants starting with "COMMAND_" such as
COMMAND_MOVE_LEFT.visible
- true to show the button and false to hide.public boolean isButtonVisible(String command)
command
- the name defined in DualList. They are constants starting with "COMMAND_" such as
COMMAND_MOVE_LEFT.public void setButtonEnabled(String command, boolean enabled)
command
- the name defined in DualList. They are constants starting with "COMMAND_" such as
COMMAND_MOVE_LEFT.enabled
- false to always disable the button.public boolean isButtonEnabled(String command)
command
- the name defined in DualList. They are constants starting with "COMMAND_" such as
COMMAND_MOVE_LEFT.@Deprecated public void setButtonPanelVisible(boolean buttonPanelVisible)
setMiddleButtonPanelVisible(boolean)
buttonPanelVisible
- the visibility@Deprecated public boolean isButtonPanelVisible()
isMiddleButtonPanelVisible()
public void setMiddleButtonPanelVisible(boolean middleButtonPanelVisible)
middleButtonPanelVisible
- the visibilitypublic boolean isMiddleButtonPanelVisible()
public void setRightButtonPanelVisible(boolean middleButtonPanelVisible)
middleButtonPanelVisible
- the visibilitypublic boolean isRightButtonPanelVisible()
public ListCellRenderer getCellRenderer()
public void setCellRenderer(ListCellRenderer cellRenderer)
setSelectedCellRenderer(javax.swing.ListCellRenderer)
is never called, the same renderer will be used for the list on the right too.cellRenderer
- the new list cell rendererpublic ListCellRenderer getSelectedCellRenderer()
getCellRenderer()
.public void setSelectedCellRenderer(ListCellRenderer selectedCellRenderer)
selectedCellRenderer
- the new list cell rendererpublic ListCellRenderer getDisabledCellRenderer()
public void setDisabledCellRenderer(ListCellRenderer disabledCellRenderer)
disabledCellRenderer
- the new disabled cell renderer.public void moveLeft()
public void moveRight()
public void moveAllLeft()
public void moveAllRight()
public void moveUp()
public void moveDown()
public void moveToTop()
public void moveToBottom()
public void setVisibleRowCount(int visibleRowCount)
visibleRowCount
- an integer specifying the preferred number of rows to display without requiring scrollingpublic int getVisibleRowCount()
visibleRowCount
from the list.visibleRowCount
property.setVisibleRowCount(int)
public boolean isAllowDuplicates()
setAllowDuplicates(boolean)
public void setAllowDuplicates(boolean allowDuplicates)
getSelectionMode()
returns DualListModel.KEEP_SELECTION
By default the flag is true to keep original behavior.allowDuplicates
- the flagsetSelectionMode(int)
public boolean isDoubleClickEnabled()
setDoubleClickEnabled(boolean)
public void setDoubleClickEnabled(boolean doubleClickEnabled)
doubleClickEnabled
- the flagprotected String getResourceString(String key)
key
- the keyprotected void performAction(String command)
command
- the command