edu.sdsc.inca
Class IncatList

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.Box
                  extended by edu.sdsc.inca.IncatList
All Implemented Interfaces:
java.awt.event.FocusListener, java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ListSelectionListener

public class IncatList
extends javax.swing.Box
implements java.awt.event.FocusListener, javax.swing.event.ListSelectionListener, java.awt.event.MouseListener

A convenience class that combines a scrollable JList and its Model. It allows listening for focus and list selection events via an ActionListener instead of a Focus/ListSelectionListener. Action commands generated by an IncatList are: DoubleClick -- user has double-clicked a selection FocusLost -- the list has lost keyboard focus FocusGained -- the list has gained keyboard focus SingleClick -- user has single-clicked a selection XXX -- user has clicked the associated button labeled with XXX Class instances prefix each of these commands with a client-supplied prefix to allow listeners to distinguish between actions from multiple IncatLists.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.Box
javax.swing.Box.AccessibleBox, javax.swing.Box.Filler
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.lang.String commandPrefix
           
protected static java.lang.String lastFind
           
protected  javax.swing.JList list
           
protected  java.awt.event.ActionListener listener
           
protected  javax.swing.DefaultListModel model
           
 
Fields inherited from class javax.swing.Box
accessibleContext
 
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
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
IncatList(java.lang.String title, java.lang.String prefix, java.lang.String buttons, java.awt.event.ActionListener listener)
          Constructs an IncatList.
 
Method Summary
 void addElement(java.lang.Object o)
          Appends an element to the end of the list.
protected static void findListElement(boolean prompt)
          Searches for an element in a list.
 int findMatchingElement(java.lang.String s)
          Returns the index of the element that matches a specific string; returns -1 if no element matches.
 void focusGained(java.awt.event.FocusEvent e)
          Forwards focus events to this list's listener.
 void focusLost(java.awt.event.FocusEvent e)
          Forwards focus events to this list's listener.
 java.awt.event.ActionListener getActionListener()
          Returns the listener notified when the user selects an element.
 java.lang.String getCommandPrefix()
          Returns the string prepended to action commands generated by this list.
 java.lang.Object getElementAt(int index)
          Return the element at a specified index.
 int getLength()
          Returns the length of the list.
 java.lang.Object getSelectedElement()
          Returns the first selected element; returns null if none.
 int getSelectedIndex()
          Returns the first selected index; returns -1 if none.
 void insertElementAt(java.lang.Object o, int index)
          Adds an element at a specified position in the list.
static javax.swing.JLabel listElementLabel(javax.swing.JList list, java.lang.Object element, boolean isSelected)
          Creates and returns a JLabel to represent a list element.
 void mouseClicked(java.awt.event.MouseEvent e)
          Forwards selection events to the list's listener.
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void removeAllElements()
          Removes all elements from the list.
 void removeElementAt(int index)
          Removes the element, if any, at a specified index.
 boolean selectMatchingElement(java.lang.String s)
          Selects the element that matches a specified string.
 void setActionListener(java.awt.event.ActionListener listener)
          Sets the listener notified when the user selects an element.
 void setCellRenderer(javax.swing.ListCellRenderer lcr)
          Sets the class that determines the presentation of list elements.
 void setCommandPrefix(java.lang.String prefix)
          Sets the string prepended to action commands generated by this list.
 void setElementAt(java.lang.Object o, int index)
          Replaces an element at a specified position in the list.
 void setElements(java.lang.Object[] elements)
          Removes all existing elements from the list and adds a specified set.
 boolean setSelectedElement(java.lang.Object o)
          Selects a specified element.
 void setSelectedIndex(int index)
          Selects the element, if any, at the specified index.
 void sort()
          Rearranges the list to display the elements in increasing alpha order.
 java.lang.Object[] toArray()
          Returns an array of the elements in this list.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Returns an array of the element in this list.
 void valueChanged(javax.swing.event.ListSelectionEvent e)
          Forwards list selections to the list's listener.
 
Methods inherited from class javax.swing.Box
createGlue, createHorizontalBox, createHorizontalGlue, createHorizontalStrut, createRigidArea, createVerticalBox, createVerticalGlue, createVerticalStrut, getAccessibleContext, setLayout
 
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, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, updateUI
 
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, 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
 

Field Detail

lastFind

protected static java.lang.String lastFind

commandPrefix

protected java.lang.String commandPrefix

list

protected javax.swing.JList list

listener

protected java.awt.event.ActionListener listener

model

protected javax.swing.DefaultListModel model
Constructor Detail

IncatList

public IncatList(java.lang.String title,
                 java.lang.String prefix,
                 java.lang.String buttons,
                 java.awt.event.ActionListener listener)
Constructs an IncatList.

Parameters:
title - title for this list, optional
prefix - text prepended to action commands generated by this list, optional
buttons - comma-delimited list of labels for buttons to attach to this list, optional
listener - listener to notify when the user acts on the list/buttons, optional
Method Detail

addElement

public void addElement(java.lang.Object o)
Appends an element to the end of the list.

Parameters:
o - the element to append

findMatchingElement

public int findMatchingElement(java.lang.String s)
Returns the index of the element that matches a specific string; returns -1 if no element matches.

Parameters:
s - the string to match
Returns:
the index of the matching element; -1 if none

getActionListener

public java.awt.event.ActionListener getActionListener()
Returns the listener notified when the user selects an element.

Returns:
the listener

getCommandPrefix

public java.lang.String getCommandPrefix()
Returns the string prepended to action commands generated by this list.

Returns:
the command prefix

getElementAt

public java.lang.Object getElementAt(int index)
Return the element at a specified index.

Parameters:
index - the requested index
Returns:
the element at index, null if none

getLength

public int getLength()
Returns the length of the list. NOTE: can't name this method either size() or getSize(), since Component declares these to return Dimension.

Returns:
the number of elements in the list

getSelectedElement

public java.lang.Object getSelectedElement()
Returns the first selected element; returns null if none.

Returns:
the first selected element; null if none

getSelectedIndex

public int getSelectedIndex()
Returns the first selected index; returns -1 if none.

Returns:
the first selected index; -1 if none

insertElementAt

public void insertElementAt(java.lang.Object o,
                            int index)
Adds an element at a specified position in the list.

Parameters:
o - the object to insert
index - the position to insert the object

removeAllElements

public void removeAllElements()
Removes all elements from the list.


removeElementAt

public void removeElementAt(int index)
Removes the element, if any, at a specified index.

Parameters:
index - the requested index

selectMatchingElement

public boolean selectMatchingElement(java.lang.String s)
Selects the element that matches a specified string.

Parameters:
s - the value to match
Returns:
true if the specified string was found/selected, otherwise false

setActionListener

public void setActionListener(java.awt.event.ActionListener listener)
Sets the listener notified when the user selects an element.

Parameters:
listener - the listener

setCellRenderer

public void setCellRenderer(javax.swing.ListCellRenderer lcr)
Sets the class that determines the presentation of list elements.

Parameters:
the - cell renderer for this list

setCommandPrefix

public void setCommandPrefix(java.lang.String prefix)
Sets the string prepended to action commands generated by this list.

Parameters:
prefix - the command prefix

setElementAt

public void setElementAt(java.lang.Object o,
                         int index)
Replaces an element at a specified position in the list.

Parameters:
o - the object to insert
index - the position to replace with the object

setElements

public void setElements(java.lang.Object[] elements)
Removes all existing elements from the list and adds a specified set.

Parameters:
elements - the set of elements to add

setSelectedElement

public boolean setSelectedElement(java.lang.Object o)
Selects a specified element.

Parameters:
o - the element to select
Returns:
true if the specified element is found/selected, false otherwise

setSelectedIndex

public void setSelectedIndex(int index)
Selects the element, if any, at the specified index.

Parameters:
index - the requested index

sort

public void sort()
Rearranges the list to display the elements in increasing alpha order.


toArray

public java.lang.Object[] toArray()
Returns an array of the elements in this list.

Returns:
an array of all elements in this list

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Returns an array of the element in this list.

Parameters:
a - the array to contain the elements--the length must match the number of elements in the IncatList, optional
Returns:
the array a with the list elements inserted

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Forwards focus events to this list's listener.

Specified by:
focusGained in interface java.awt.event.FocusListener

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Forwards focus events to this list's listener.

Specified by:
focusLost in interface java.awt.event.FocusListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Forwards selection events to the list's listener.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent e)
Forwards list selections to the list's listener.

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener

findListElement

protected static void findListElement(boolean prompt)
Searches for an element in a list.

Parameters:
prompt - ask the user to enter a search text; if false, reuse the most recent text

listElementLabel

public static javax.swing.JLabel listElementLabel(javax.swing.JList list,
                                                  java.lang.Object element,
                                                  boolean isSelected)
Creates and returns a JLabel to represent a list element.

Parameters:
list - the list that contains the element
element - the element to represent
isSelected - indicates whether the element is currently selected
Returns:
a JLabel representation of the element in the list