public class ComponentList<E extends ComponentProducer>
extends javax.swing.JPanel
implements javax.swing.Scrollable, java.lang.Iterable<E>
ComponentList
class is similar to a Swing
JList
but with a simplified model and operations. It
lays out a list of ComponentProducer
objects from top
to bottom and allows them to be selected, removed, added, and so
on. A change in the list selection is signaled using a property
change event given by SELECTION_PROPERTY
.
The list may be placed inside a scrollable window. The scrolling
behaviour works under the assumption that all components in the
list have the same height. The user may set the number of visible
components using the setVisibleRowCount()
method.
javax.swing.JPanel.AccessibleJPanel
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SELECTION_PROPERTY
The selection property event used to signal changes in the
selected elements.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
ComponentList()
Creates a new empty component list.
|
Modifier and Type | Method and Description |
---|---|
void |
addElement(E producer)
Adds a new component to the end of the list.
|
void |
addElement(int index,
E producer)
Adds a new component at the specified index in the list.
|
void |
clear()
Clears the list of all components.
|
E |
getElement(int index)
Gets the component at the specified index.
|
int |
getElements()
Gets the number of components in the list.
|
java.awt.Dimension |
getPreferredScrollableViewportSize() |
int |
getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
int orientation,
int direction) |
boolean |
getScrollableTracksViewportHeight() |
boolean |
getScrollableTracksViewportWidth() |
int |
getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
int orientation,
int direction) |
int[] |
getSelectedIndices()
Gets the currently selected indices.
|
int |
getVisibleRowCount()
Gets the visible rows in this list.
|
int |
indexOf(E producer)
Gets the index of a component producer in the list.
|
java.util.Iterator<E> |
iterator()
Gets an iterator over the component producers in the list.
|
static void |
main(java.lang.String[] argv)
Tests this class.
|
void |
moveElement(int source,
int dest)
Moves the component between the specified indices.
|
boolean |
removeElement(E producer)
Removes the specified component from the list.
|
E |
removeElement(int index)
Removes the component at the specified index.
|
void |
setSelectable(boolean selectableFlag)
Sets the selectable flag.
|
void |
setSelectionInterval(int start,
int end)
Sets the selection indices between the specified start and end
inclusive.
|
void |
setVisibleRowCount(int visibleRowCount)
Sets the number of visible rows in this list.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, setVisible, unregisterKeyboardAction, update
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
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 java.lang.String SELECTION_PROPERTY
public void setSelectable(boolean selectableFlag)
selectableFlag
- the selectable flag, true if rows should be
selectable or false if not.public void clear()
public void addElement(E producer)
producer
- the component producer to add to the list.public void addElement(int index, E producer)
index
- the index to add the component at. The component is
inserted at the index and all component indices after the inserted
index are incremented.producer
- the component producer to add to the list.public boolean removeElement(E producer)
producer
- the component producer to remove.public E removeElement(int index)
index
- the index of the component to remove.public void moveElement(int source, int dest)
source
- the source index for the component to move.dest
- the destination index to insert a new component. The
destination index is relative to the indices of elements after the
removal operation has happened.public int getElements()
public int[] getSelectedIndices()
public void setSelectionInterval(int start, int end)
start
- the starting index for the selection.end
- the ending index for selection.java.lang.IndexOutOfBoundsException
- if either index is out of bounds.public E getElement(int index)
index
- to index of the component producer to retrieve.java.lang.IndexOutOfBoundsException
- if the index is out of range.public java.util.Iterator<E> iterator()
iterator
in interface java.lang.Iterable<E extends ComponentProducer>
public int indexOf(E producer)
producer
- the component producer to search for.public void setVisibleRowCount(int visibleRowCount)
visibleRowCount
- the desired number of visible rows.public int getVisibleRowCount()
public java.awt.Dimension getPreferredScrollableViewportSize()
getPreferredScrollableViewportSize
in interface javax.swing.Scrollable
public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
getScrollableBlockIncrement
in interface javax.swing.Scrollable
public boolean getScrollableTracksViewportHeight()
getScrollableTracksViewportHeight
in interface javax.swing.Scrollable
public boolean getScrollableTracksViewportWidth()
getScrollableTracksViewportWidth
in interface javax.swing.Scrollable
public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
getScrollableUnitIncrement
in interface javax.swing.Scrollable
public static void main(java.lang.String[] argv)
argv
- the array of command line parameters.