Package noaa.coastwatch.gui.visual
Class ComponentList<E extends ComponentProducer>
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
noaa.coastwatch.gui.visual.ComponentList<E>
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Iterable<E>
,Accessible
,Scrollable
public class ComponentList<E extends ComponentProducer>
extends JPanel
implements Scrollable, Iterable<E>
The 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.
- Since:
- 3.1.7
- Author:
- Peter Hollemans
- See Also:
-
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
Modifier and TypeFieldDescriptionstatic final String
The selection property event used to signal changes in the selected elements.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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addElement
(int index, E producer) Adds a new component at the specified index in the list.void
addElement
(E producer) Adds a new component to the end of the list.void
clear()
Clears the list of all components.getElement
(int index) Gets the component at the specified index.int
Gets the number of components in the list.int
getScrollableBlockIncrement
(Rectangle visibleRect, int orientation, int direction) boolean
boolean
int
getScrollableUnitIncrement
(Rectangle visibleRect, int orientation, int direction) int[]
Gets the currently selected indices.int
Gets the visible rows in this list.int
Gets the index of a component producer in the list.iterator()
Gets an iterator over the component producers in the list.static void
Tests this class.void
moveElement
(int source, int dest) Moves the component between the specified indices.removeElement
(int index) Removes the component at the specified index.boolean
removeElement
(E producer) Removes the specified component from the list.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.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, 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, 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, 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, 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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
SELECTION_PROPERTY
The selection property event used to signal changes in the selected elements.- See Also:
-
-
Constructor Details
-
ComponentList
public ComponentList()Creates a new empty component list.
-
-
Method Details
-
setSelectable
public void setSelectable(boolean selectableFlag) Sets the selectable flag. When on, the list rows are selectable and change their background colour when selected. When off, rows are not selectable and keep their default background color even when clicked.- Parameters:
selectableFlag
- the selectable flag, true if rows should be selectable or false if not.
-
clear
public void clear()Clears the list of all components. -
addElement
Adds a new component to the end of the list.- Parameters:
producer
- the component producer to add to the list.
-
addElement
Adds a new component at the specified index in the list.- Parameters:
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.
-
removeElement
Removes the specified component from the list.- Parameters:
producer
- the component producer to remove.- Returns:
- true if the component was removed, false otherwise.
-
removeElement
Removes the component at the specified index.- Parameters:
index
- the index of the component to remove.- Returns:
- the removed component producer.
-
moveElement
public void moveElement(int source, int dest) Moves the component between the specified indices.- Parameters:
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.
-
getElements
public int getElements()Gets the number of components in the list.- Returns:
- the number of components.
-
getSelectedIndices
public int[] getSelectedIndices()Gets the currently selected indices.- Returns:
- the array of selected indices, possible zero length if no rows are selected.
-
setSelectionInterval
public void setSelectionInterval(int start, int end) Sets the selection indices between the specified start and end inclusive.- Parameters:
start
- the starting index for the selection.end
- the ending index for selection.- Throws:
IndexOutOfBoundsException
- if either index is out of bounds.
-
getElement
Gets the component at the specified index.- Parameters:
index
- to index of the component producer to retrieve.- Returns:
- the component producer at the specified index.
- Throws:
IndexOutOfBoundsException
- if the index is out of range.
-
iterator
Gets an iterator over the component producers in the list.- Specified by:
iterator
in interfaceIterable<E extends ComponentProducer>
- Returns:
- the iterator over component producers.
-
indexOf
Gets the index of a component producer in the list.- Parameters:
producer
- the component producer to search for.- Returns:
- the index of the first occurrence of the producer, or -1 if this list does not contain the producer.
-
setVisibleRowCount
public void setVisibleRowCount(int visibleRowCount) Sets the number of visible rows in this list. If the list is inside a scroll window, the preferred size of the viewport is set to display the specified number of rows. By default, the visible row count is 8.- Parameters:
visibleRowCount
- the desired number of visible rows.
-
getVisibleRowCount
public int getVisibleRowCount()Gets the visible rows in this list.- Returns:
- the number of visible rows in the component list.
-
getPreferredScrollableViewportSize
- Specified by:
getPreferredScrollableViewportSize
in interfaceScrollable
-
getScrollableBlockIncrement
- Specified by:
getScrollableBlockIncrement
in interfaceScrollable
-
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()- Specified by:
getScrollableTracksViewportHeight
in interfaceScrollable
-
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()- Specified by:
getScrollableTracksViewportWidth
in interfaceScrollable
-
getScrollableUnitIncrement
- Specified by:
getScrollableUnitIncrement
in interfaceScrollable
-
main
Tests this class.- Parameters:
argv
- the array of command line parameters.
-