Package adams.gui.core
Class BaseListWithButtons
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
- Direct Known Subclasses:
FileListWithButtons
,SearchableBaseListWithButtons
public class BaseListWithButtons extends AbstractDoubleClickableComponentWithButtons<BaseList>
Graphical component that consists of a BaseTable with buttons on the right-hand side.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- 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 Modifier and Type Field Description protected ListDataListener
m_CountModelListener
the model listener for updating the counts.-
Fields inherited from class adams.gui.core.AbstractDoubleClickableComponentWithButtons
m_DoubleClickAction, m_DoubleClickButton
-
Fields inherited from class adams.gui.core.AbstractComponentWithButtons
m_Component, m_LabelInfo, m_PanelAll, m_PanelInfo, m_ScrollPane
-
Fields inherited from class adams.gui.core.BasePanelWithButtons
m_LayoutButtons, m_PanelButtons
-
Fields inherited from class adams.gui.core.BasePanel
m_FileChooser
-
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
Constructors Constructor Description BaseListWithButtons()
The default constructor.BaseListWithButtons(ListModel model)
Initializes the list with the specified model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListSelectionListener(ListSelectionListener listener)
Adds a listener to the list, to be notified each time a change to the selection occurs; the preferred way of listening for selection state changes.void
addRemoveItemsListener(RemoveItemsListener l)
Adds the remove items listener to its internal list.boolean
canMoveDown()
checks whether the selected items can be moved down.boolean
canMoveUp()
checks whether the selected items can be moved up.protected BaseList
createComponent()
Creates the component to use in the panel.ListModel
getModel()
Returns the underlying list model.int
getSelectedIndex()
Returns the smallest selected cell index; the selection when only a single item is selected in the list.int[]
getSelectedIndices()
Returns an array of all of the selected indices, in increasing order.Object
getSelectedValue()
Returns the value for the smallest selected cell index; the selected value when only a single item is selected in the list.List
getSelectedValuesList()
Returns a list of all the selected items, in increasing order based on their indices in the list.int
getSelectionMode()
Returns the current selection mode for the list.ListSelectionModel
getSelectionModel()
Returns the current selection model.void
invertSelection()
Inverts the current selection.protected boolean
isValidDoubleClick(MouseEvent e)
Checks whether the double click is valid for this component.void
moveBottom()
moves the selected items to the end.void
moveDown()
moves the selected item down by 1.void
moveTop()
moves the selected items to the top.void
moveUp()
moves the selected items up by 1.void
removeListSelectionListener(ListSelectionListener listener)
Removes a selection listener from the list.void
removeRemoveItemsListener(RemoveItemsListener l)
Removes the remove items listener from its internal list.boolean
requiresScrollPane()
Returns whether the component requires a JScrollPane around it.void
selectAll()
Selects all items.void
selectNone()
Select no items.void
setInfoVisible(boolean value)
Whether to display the information JLabel or not.void
setModel(ListModel model)
Sets the model that represents the contents or "value" of the list, notifies property change listeners, and then clears the list's selection.void
setSelectedIndex(int index)
Selects a single cell.void
setSelectedIndices(int[] indices)
Changes the selection to be the set of indices specified by the given array.void
setSelectedValue(Object anObject, boolean shouldScroll)
Selects the specified object from the list.void
setSelectionMode(int selectionMode)
Sets the selection mode for the list.void
setSelectionModel(ListSelectionModel selectionModel)
Sets theselectionModel
for the list to a non-null
ListSelectionModel
implementation.protected void
updateCounts()
Updates the information about the counts.protected void
updateCountsModelListener(ListModel dataModel)
Updates the table model's listener for updating the counts.-
Methods inherited from class adams.gui.core.AbstractDoubleClickableComponentWithButtons
getDoubleClickAction, getDoubleClickButton, initGUI, setDoubleClickAction, setDoubleClickButton
-
Methods inherited from class adams.gui.core.AbstractComponentWithButtons
addKeyListener, getComponent, getScrollPane, isInfoVisible, removeKeyListener, updateInfo
-
Methods inherited from class adams.gui.core.BasePanelWithButtons
addToButtonsPanel, clearButtonsPanel, removeFromButtonsPanel
-
Methods inherited from class adams.gui.core.BasePanel
afterHide, afterShow, beforeHide, beforeShow, closeParent, finishInit, getParentChild, getParentDialog, getParentFrame, getParentInternalFrame, getParentTitle, initFileChooser, initialize, main, printErrorMessage, printException, saveComponent, setEnabledCascade, setEnabledCascade, setParentTitle, setVisible
-
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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, 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, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, 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, 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, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
m_CountModelListener
protected ListDataListener m_CountModelListener
the model listener for updating the counts.
-
-
Constructor Detail
-
BaseListWithButtons
public BaseListWithButtons()
The default constructor.
-
BaseListWithButtons
public BaseListWithButtons(ListModel model)
Initializes the list with the specified model.- Parameters:
model
- the model to use
-
-
Method Detail
-
requiresScrollPane
public boolean requiresScrollPane()
Returns whether the component requires a JScrollPane around it.- Specified by:
requiresScrollPane
in classAbstractComponentWithButtons<BaseList>
- Returns:
- true if the component requires a JScrollPane
-
createComponent
protected BaseList createComponent()
Creates the component to use in the panel. If a- Specified by:
createComponent
in classAbstractComponentWithButtons<BaseList>
- Returns:
- the component
-
isValidDoubleClick
protected boolean isValidDoubleClick(MouseEvent e)
Checks whether the double click is valid for this component.- Specified by:
isValidDoubleClick
in classAbstractDoubleClickableComponentWithButtons<BaseList>
- Parameters:
e
- the mouse event of the double click- Returns:
- true if valid double click
-
setModel
public void setModel(ListModel model)
Sets the model that represents the contents or "value" of the list, notifies property change listeners, and then clears the list's selection.This is a JavaBeans bound property.
- Parameters:
model
- theListModel
that provides the list of items for display
-
getModel
public ListModel getModel()
Returns the underlying list model.- Returns:
- the underlying list model
-
addListSelectionListener
public void addListSelectionListener(ListSelectionListener listener)
Adds a listener to the list, to be notified each time a change to the selection occurs; the preferred way of listening for selection state changes.JList
takes care of listening for selection state changes in the selection model, and notifies the given listener of each change.ListSelectionEvent
s sent to the listener have asource
property set to this list.- Parameters:
listener
- theListSelectionListener
to add
-
removeListSelectionListener
public void removeListSelectionListener(ListSelectionListener listener)
Removes a selection listener from the list.- Parameters:
listener
- theListSelectionListener
to remove
-
getSelectedIndices
public int[] getSelectedIndices()
Returns an array of all of the selected indices, in increasing order.- Returns:
- all of the selected indices, in increasing order, or an empty array if nothing is selected
- See Also:
#removeSelectionInterval
,addListSelectionListener(javax.swing.event.ListSelectionListener)
-
setSelectedIndex
public void setSelectedIndex(int index)
Selects a single cell. Does nothing if the given index is greater than or equal to the model size. This is a convenience method that usessetSelectionInterval
on the selection model. Refer to the documentation for the selection model class being used for details on how values less than0
are handled.- Parameters:
index
- the index of the cell to select- See Also:
ListSelectionModel.setSelectionInterval(int, int)
,#isSelectedIndex
,addListSelectionListener(javax.swing.event.ListSelectionListener)
-
setSelectedIndices
public void setSelectedIndices(int[] indices)
Changes the selection to be the set of indices specified by the given array. Indices greater than or equal to the model size are ignored. This is a convenience method that clears the selection and then usesaddSelectionInterval
on the selection model to add the indices. Refer to the documentation of the selection model class being used for details on how values less than0
are handled.- Parameters:
indices
- an array of the indices of the cells to select,non-null
- Throws:
NullPointerException
- if the given array isnull
- See Also:
ListSelectionModel.addSelectionInterval(int, int)
,#isSelectedIndex
,addListSelectionListener(javax.swing.event.ListSelectionListener)
-
getSelectedValuesList
public List getSelectedValuesList()
Returns a list of all the selected items, in increasing order based on their indices in the list.- Returns:
- the selected items, or an empty list if nothing is selected
-
getSelectedIndex
public int getSelectedIndex()
Returns the smallest selected cell index; the selection when only a single item is selected in the list. When multiple items are selected, it is simply the smallest selected index. Returns-1
if there is no selection.This method is a cover that delegates to
getMinSelectionIndex
.- Returns:
- the smallest selected cell index
-
getSelectedValue
public Object getSelectedValue()
Returns the value for the smallest selected cell index; the selected value when only a single item is selected in the list. When multiple items are selected, it is simply the value for the smallest selected index. Returnsnull
if there is no selection.This is a convenience method that simply returns the model value for
getMinSelectionIndex
.- Returns:
- the first selected value
-
setSelectedValue
public void setSelectedValue(Object anObject, boolean shouldScroll)
Selects the specified object from the list.- Parameters:
anObject
- the object to selectshouldScroll
-true
if the list should scroll to display the selected object, if one exists; otherwisefalse
-
moveUp
public void moveUp()
moves the selected items up by 1.
-
moveDown
public void moveDown()
moves the selected item down by 1.
-
moveTop
public void moveTop()
moves the selected items to the top.
-
moveBottom
public void moveBottom()
moves the selected items to the end.
-
canMoveUp
public boolean canMoveUp()
checks whether the selected items can be moved up.- Returns:
- true if the selected items can be moved
-
canMoveDown
public boolean canMoveDown()
checks whether the selected items can be moved down.- Returns:
- true if the selected items can be moved
-
setSelectionMode
public void setSelectionMode(int selectionMode)
Sets the selection mode for the list. This is a cover method that sets the selection mode directly on the selection model.The following list describes the accepted selection modes:
ListSelectionModel.SINGLE_SELECTION
- Only one list index can be selected at a time. In this mode,setSelectionInterval
andaddSelectionInterval
are equivalent, both replacing the current selection with the index represented by the second argument (the "lead").ListSelectionModel.SINGLE_INTERVAL_SELECTION
- Only one contiguous interval can be selected at a time. In this mode,addSelectionInterval
behaves likesetSelectionInterval
(replacing the current selection}, unless the given interval is immediately adjacent to or overlaps the existing selection, and can be used to grow the selection.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
- In this mode, there's no restriction on what can be selected. This mode is the default.
- Parameters:
selectionMode
- the selection mode- See Also:
getSelectionMode()
-
getSelectionMode
public int getSelectionMode()
Returns the current selection mode for the list. This is a cover method that delegates to the method of the same name on the list's selection model.- Returns:
- the current selection mode
- See Also:
setSelectionMode(int)
-
getSelectionModel
public ListSelectionModel getSelectionModel()
Returns the current selection model. The selection model maintains the selection state of the list. See the class level documentation for more details.- Returns:
- the
ListSelectionModel
that maintains the list's selections - See Also:
setSelectionModel(javax.swing.ListSelectionModel)
,ListSelectionModel
-
setSelectionModel
public void setSelectionModel(ListSelectionModel selectionModel)
Sets theselectionModel
for the list to a non-null
ListSelectionModel
implementation. The selection model handles the task of making single selections, selections of contiguous ranges, and non-contiguous selections.This is a JavaBeans bound property.
- Parameters:
selectionModel
- theListSelectionModel
that implements the selections
-
addRemoveItemsListener
public void addRemoveItemsListener(RemoveItemsListener l)
Adds the remove items listener to its internal list.- Parameters:
l
- the listener to add
-
removeRemoveItemsListener
public void removeRemoveItemsListener(RemoveItemsListener l)
Removes the remove items listener from its internal list.- Parameters:
l
- the listener to remove
-
setInfoVisible
public void setInfoVisible(boolean value)
Whether to display the information JLabel or not.- Overrides:
setInfoVisible
in classAbstractComponentWithButtons<BaseList>
- Parameters:
value
- if true then the information is being displayed
-
updateCountsModelListener
protected void updateCountsModelListener(ListModel dataModel)
Updates the table model's listener for updating the counts.- Parameters:
dataModel
- the model to update
-
updateCounts
protected void updateCounts()
Updates the information about the counts.
-
selectAll
public void selectAll()
Selects all items.
-
selectNone
public void selectNone()
Select no items.
-
invertSelection
public void invertSelection()
Inverts the current selection.
-
-