be.ugent.caagt.swirl.lists
Class CellList

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by be.ugent.caagt.swirl.lists.CellList
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.swing.event.ListDataListener, javax.swing.Scrollable

public class CellList
extends javax.swing.JComponent
implements javax.swing.Scrollable, javax.swing.event.ListDataListener

List component in which list items are layed out as cells in a grid. The functionality is the same as that of JList except for the following:

This list component uses a cellRenderer delegate of type CellListCellRenderer to paint the visible cells in the list and to obtain the correct tool tip information for that cell.

See Also:
Serialized Form

Nested Class Summary
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
CellList(javax.swing.ListModel dataModel, int cellWidth, int cellHeight, int numberOfColumns)
          Construct a list of this type for the given model, with the given cell size.
 
Method Summary
 void contentsChanged(javax.swing.event.ListDataEvent e)
           
 void doLayout()
           
 void ensureIndexIsVisible(int index)
          Scrolls the viewport to make the specified cell completely visible.
 java.awt.Rectangle getCellBounds(int index0, int index1)
          Returns the bounds of the specified range of items in component coordinates.Returns null if index isn't valid.
 int getCellHeight()
          Height of a grid cell.
 CellListCellRenderer getCellRenderer()
          Return the cell renderer used by this list.
 int getCellWidth()
          Width of a grid cell.
 java.awt.Point getDropLocation()
          Return the last drag-and-drop location where this component is a target.
 java.awt.Dimension getMinimumSize()
           
 javax.swing.ListModel getModel()
          Return the current data model.
 java.awt.Dimension getPreferredScrollableViewportSize()
           
 java.awt.Dimension getPreferredSize()
           
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Returns the distance to scroll vertically to expose the next or previous block.
 boolean getScrollableTracksViewportHeight()
           
 boolean getScrollableTracksViewportWidth()
           
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Returns the distance to scroll vertically to expose the next or previous row.
 java.lang.Object getSelectedValue()
          Returns the first selected value, or null if the selection is empty.
 java.lang.Object[] getSelectedValues()
          Returns an array of the values for the selected cells.
 javax.swing.ListSelectionModel getSelectionModel()
          Return the current selection model.
 java.lang.String getToolTipText(java.awt.event.MouseEvent event)
          Overrides JComponent's getToolTipText method in order to allow the renderer's tips to be used if it has text set.
 java.awt.Point indexToLocation(int index)
          Return the top left coordinate of the cell with given index, or null if the index is not valid.
 void initActionMap()
          Initialize the action map.
 void intervalAdded(javax.swing.event.ListDataEvent e)
           
 void intervalRemoved(javax.swing.event.ListDataEvent e)
           
 boolean isDragEnabled()
          Is dragging on this component enabled?
 boolean isDropInProgress()
          Is a drag-and-drop operation in progress where this component is a target?
 int locationToIndex(java.awt.Point location)
          Convert a point in component coordinates to the index of the cell at that location, or -1 if there is no such cell.
protected  void paintComponent(java.awt.Graphics g)
           
 void setCellHeight(int cellHeight)
          Set the height of a grid cell.
 void setCellRenderer(CellListCellRenderer cellRenderer)
          Set the cell renderer.
 void setCellSize(int cellWidth, int cellHeight)
          Set width and height of a grid cell.
 void setCellWidth(int cellWidth)
          Set the width of a grid cell.
 void setDragEnabled(boolean dragEnabled)
          Indicate whether dragging on this component should be enabled.
 void setDropTarget(java.awt.dnd.DropTarget dt)
           
 void setModel(javax.swing.ListModel model)
          Sets a new data model and clears the selection.
 void setNumberOfColumns(int numberOfColumns)
          Set the number of columns to use in this list.
 void setSelectionModel(javax.swing.ListSelectionModel selectionModel)
          Set or change the selection model.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, 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, 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, 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
 

Constructor Detail

CellList

public CellList(javax.swing.ListModel dataModel,
                int cellWidth,
                int cellHeight,
                int numberOfColumns)
Construct a list of this type for the given model, with the given cell size.

Parameters:
cellWidth - width of every grid cell
cellHeight - height of every grid cell
numberOfColumns - initial number of columns
Method Detail

setNumberOfColumns

public void setNumberOfColumns(int numberOfColumns)
Set the number of columns to use in this list.

Parameters:
numberOfColumns - New value of property numberOfColumns.

getCellWidth

public int getCellWidth()
Width of a grid cell.

Returns:
Value of property cellWidth.

setCellWidth

public void setCellWidth(int cellWidth)
Set the width of a grid cell.

Parameters:
cellWidth - New value of property cellWidth.

getCellHeight

public int getCellHeight()
Height of a grid cell.

Returns:
Value of property cellHeight.

setCellHeight

public void setCellHeight(int cellHeight)
Set the height of a grid cell.

Parameters:
cellHeight - New value of property cellHeight.

getSelectionModel

public javax.swing.ListSelectionModel getSelectionModel()
Return the current selection model.


setCellSize

public void setCellSize(int cellWidth,
                        int cellHeight)
Set width and height of a grid cell.

Parameters:
cellWidth - New value of property cellWidth.
cellHeight - New value of property cellHeight.

setSelectionModel

public final void setSelectionModel(javax.swing.ListSelectionModel selectionModel)
Set or change the selection model.


getModel

public javax.swing.ListModel getModel()
Return the current data model.


setModel

public void setModel(javax.swing.ListModel model)
Sets a new data model and clears the selection.


getCellRenderer

public CellListCellRenderer getCellRenderer()
Return the cell renderer used by this list.


setCellRenderer

public void setCellRenderer(CellListCellRenderer cellRenderer)
Set the cell renderer.


getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent event)
Overrides JComponent's getToolTipText method in order to allow the renderer's tips to be used if it has text set.

Overrides:
getToolTipText in class javax.swing.JComponent
See Also:
JComponent.getToolTipText()

locationToIndex

public int locationToIndex(java.awt.Point location)
Convert a point in component coordinates to the index of the cell at that location, or -1 if there is no such cell.


indexToLocation

public java.awt.Point indexToLocation(int index)
Return the top left coordinate of the cell with given index, or null if the index is not valid.


getCellBounds

public java.awt.Rectangle getCellBounds(int index0,
                                        int index1)
Returns the bounds of the specified range of items in component coordinates.Returns null if index isn't valid.

Parameters:
index0 - the index of the first cell in the range
index1 - the index of the last cell in the range
Returns:
the bounds of the indexed cells in pixels

paintComponent

protected void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

doLayout

public void doLayout()
Overrides:
doLayout in class java.awt.Container

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overrides:
getMinimumSize in class javax.swing.JComponent

ensureIndexIsVisible

public void ensureIndexIsVisible(int index)
Scrolls the viewport to make the specified cell completely visible. Only works when the list is in a scroll pane.

Parameters:
index - the index of the cell to make visible

getSelectedValues

public java.lang.Object[] getSelectedValues()
Returns an array of the values for the selected cells. The returned values are sorted in increasing index order.


getSelectedValue

public java.lang.Object getSelectedValue()
Returns the first selected value, or null if the selection is empty.


getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Returns the distance to scroll vertically to expose the next or previous row. If the top (resp. bottom) row was only partially exposed it now becomes fully exposed.

Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Returns the distance to scroll vertically to expose the next or previous block. We are using the follows rules:

Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable

intervalRemoved

public void intervalRemoved(javax.swing.event.ListDataEvent e)
Specified by:
intervalRemoved in interface javax.swing.event.ListDataListener

intervalAdded

public void intervalAdded(javax.swing.event.ListDataEvent e)
Specified by:
intervalAdded in interface javax.swing.event.ListDataListener

contentsChanged

public void contentsChanged(javax.swing.event.ListDataEvent e)
Specified by:
contentsChanged in interface javax.swing.event.ListDataListener

initActionMap

public final void initActionMap()
Initialize the action map.


setDragEnabled

public void setDragEnabled(boolean dragEnabled)
Indicate whether dragging on this component should be enabled.


isDragEnabled

public boolean isDragEnabled()
Is dragging on this component enabled?


isDropInProgress

public boolean isDropInProgress()
Is a drag-and-drop operation in progress where this component is a target?


getDropLocation

public java.awt.Point getDropLocation()
Return the last drag-and-drop location where this component is a target.


setDropTarget

public void setDropTarget(java.awt.dnd.DropTarget dt)
Overrides:
setDropTarget in class java.awt.Component