Saturday, February 23, 2008

ImageFlow Swing Component

ImageFlow is a Java Swing component that is very similar to the CoverFlow control in Apple's iTunes.

Background
A few years ago, Romain Guy created a very cool demo application called Music Shelf. Romain has an extensive explanation of the math behind this demo on his web site:

http://www.curious-creature.org/2005/07/09/a-music-shelf-in-java2d/
Changes
The ImageFlow is component is pretty much the same as Romain's MusicShelf demo behind the scenes. The ImageFlow component has added new methods to make it similar to JList. This component has also removed the hard coded images in the code. Below is a more details list of changes.
2/17/2008 Changes
  • Removed image names and label strings from the code.
  • Images don't need to be part of the jar
  • Removed the CD case painting
  • Add support for non-square images (images are scaled proportionately)
  • Added the ability to specify a directory and have it load the images from that directory.
  • Added methods similar to those on a JList. These methods include: getSelectedIndex, getSelectedValue, isSelectedIndex, setSelectedIndex,
    addListSelectionListener, removeListSelectionListener.

Screenshot


Usage
Although the ImageFlow component doesn't extend JList, the methods to use it are very similar to a JList.


Constructors

ImageFlow(List items)
This constructs an ImageFlow component with a list of ImageFlowItem. An ImageFlowItem contains the image information and the text to display under the item.

ImageFlow(File directory)
This constructs an ImageFlow component that will load the images from a specified directory.

General Use

To get and set the selected items, the following methods can be used:

getSelectedIndex()
getSelectedValue()
isSelectedIndex(int index)
setSelectedIndex(int index)

To listen for the selected item changing in the component, a listener can be added to the ImageFlow component using the addListSelectionListener method.

Download
ImageFlow Component

Feedback
If you have questions, comments, or suggestions, post them below.

0 comments: