net.sourceforge.pavlov.randommedia
Class RandomImageFactory

java.lang.Object
  extended by net.sourceforge.pavlov.randommedia.AbstractRandomMediaFactory
      extended by net.sourceforge.pavlov.randommedia.RandomImageFactory
All Implemented Interfaces:
ActionListener, EventListener, RandomURLProvider

public class RandomImageFactory
extends AbstractRandomMediaFactory

RandomImageFactory provides an interface for retrieving a random image from a filesystem directory tree. Images can be individual files or JAR files of images. JAR files are treated as directories. Directories can be interactively enabled and disabled.

This implementation is thread safe and is an example of the Singleton OOD design pattern.

Note: If the directory tree has closed loops, it will make the current implementation go into an infinite loop. For example if b is a subdirectory of a (a/b) and c is a link in b to a (a/b/c->a), this implementation will add an infinite number of copies of the a and b directories.


Constructor Summary
RandomImageFactory()
          Creates a new RandomImageFactory instance.
RandomImageFactory(String rootDir)
          Creates a new RandomImageFactory instance.
 
Method Summary
 void clearCache()
          Clears the cache maintained in the ImageLoader.
protected  ZipCapableFileFilter getFileFilter()
          Describe getFileFilter method here.
static int getGlobalCacheObjectCount()
           
 CacheObject getRandomCacheObject()
          Gets an image embedded in a CacheObject, which provides some additional information about the image.
 ImageIcon getRandomImageIcon(int size)
          Gets a random image as an ImageIcon.
 
Methods inherited from class net.sourceforge.pavlov.randommedia.AbstractRandomMediaFactory
actionPerformed, addMediaRootChangedListener, clearDirectories, disableDirectory, enableDirectory, enableDirectory, getNumberOfDisabledItems, getNumberOfEnabledItems, getNumberOfTotalItems, getRandomURL, getRootDirectory, getSubDirectoryNames, isDirectoryEnabled, notifyListeners, refresh, setRootDirectory, setRootDirectory, toggleEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomImageFactory

public RandomImageFactory()
Creates a new RandomImageFactory instance.


RandomImageFactory

public RandomImageFactory(String rootDir)
Creates a new RandomImageFactory instance.

Parameters:
rootDir - a String value
Method Detail

clearCache

public void clearCache()
Clears the cache maintained in the ImageLoader. Useful after enabling or disabling directories and changing the root directory.

Specified by:
clearCache in class AbstractRandomMediaFactory

getRandomCacheObject

public CacheObject getRandomCacheObject()
Gets an image embedded in a CacheObject, which provides some additional information about the image.

Returns:
a CacheObject value with an random ImageIcon as its CacheObject.object field.

getRandomImageIcon

public ImageIcon getRandomImageIcon(int size)
Gets a random image as an ImageIcon.

Parameters:
size - an int value
Returns:
an ImageIcon value

getGlobalCacheObjectCount

public static int getGlobalCacheObjectCount()

getFileFilter

protected ZipCapableFileFilter getFileFilter()
Describe getFileFilter method here.

Specified by:
getFileFilter in class AbstractRandomMediaFactory
Returns:
a ZipCapableFileFilter value