net.sourceforge.pavlov.randommedia
Class AbstractRandomMediaFactory

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

public abstract class AbstractRandomMediaFactory
extends Object
implements ActionListener, RandomURLProvider

This is a base class for random media factories. A random media factory is supplied with a directory tree or JAR file or mixture of the two, and randomly supplies a media object (i.e. an image, a sound) from the files. Implementations often will require caching/preloading.


Constructor Summary
AbstractRandomMediaFactory()
          Creates a new AbstractRandomMediaFactory instance.
AbstractRandomMediaFactory(String rootDir)
          Creates a new AbstractRandomMediaFactory instance.
 
Method Summary
 void actionPerformed(ActionEvent e)
          Toggles the enabled state of a RandomMediaDirectory named by the ActionEvent's ActionCommand.
 void addMediaRootChangedListener(MediaRootChangedListener who)
          Adds an object that wants to be notified when the media directory structure has changed.
abstract  void clearCache()
          Clears any caching mechanism.
 void clearDirectories()
          Removes all directories and clears any cache.
 void disableDirectory(String dirName)
          Disables the named RandomMediaDirectory.
 void enableDirectory(RandomMediaDirectory directory)
          This enables, i.e.
 void enableDirectory(String dirName)
          Enables the named RandomMediaDirectory.
protected abstract  ZipCapableFileFilter getFileFilter()
          Describe getFileFilter method here.
 int getNumberOfDisabledItems()
          Returns a count of items in disabled directories.
 int getNumberOfEnabledItems()
          Returns a count of items in enabled directories.
 int getNumberOfTotalItems()
          Returns a count of items in enabled and disabled directories.
 URL getRandomURL()
          Returns a random URL from one of the enabled directories.
 String getRootDirectory()
          getRootDirectory returns a String representation of this factory's root directory.
 String[] getSubDirectoryNames()
          Returns a string array of subdirectory names.
 boolean isDirectoryEnabled(String dirName)
          Returns whether the named directory is enabled or not.
protected  void notifyListeners()
          Lets all the MediaRootChangedListeners know that the MediaRoot has changed.
 void refresh()
          Synch the in-memory representation up with the filesystem representation.
 void setRootDirectory(File directory)
          Sets the root directory for this media factory, clears the cache as per clearCache() and refreshes its state with refresh().
 void setRootDirectory(String dir)
           
 void toggleEnabled(String dirName)
          Toggles the enabled state of the named RandomMediaDirectory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRandomMediaFactory

public AbstractRandomMediaFactory()
Creates a new AbstractRandomMediaFactory instance. Uses the directory "resources/images" as its root directory.


AbstractRandomMediaFactory

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

Parameters:
rootDir - a String value
Method Detail

getFileFilter

protected abstract ZipCapableFileFilter getFileFilter()
Describe getFileFilter method here.

Returns:
a ZipCapableFileFilter value

clearCache

public abstract void clearCache()
Clears any caching mechanism.


getRootDirectory

public String getRootDirectory()
getRootDirectory returns a String representation of this factory's root directory.

Returns:
a String value

setRootDirectory

public void setRootDirectory(String dir)

setRootDirectory

public void setRootDirectory(File directory)
Sets the root directory for this media factory, clears the cache as per clearCache() and refreshes its state with refresh().

Parameters:
directory - a File value

notifyListeners

protected void notifyListeners()
Lets all the MediaRootChangedListeners know that the MediaRoot has changed.


addMediaRootChangedListener

public void addMediaRootChangedListener(MediaRootChangedListener who)
Adds an object that wants to be notified when the media directory structure has changed.

Parameters:
who - a MediaRootChangedListener value

refresh

public void refresh()
Synch the in-memory representation up with the filesystem representation.


enableDirectory

public void enableDirectory(RandomMediaDirectory directory)
This enables, i.e. allows random media to be selected from, the given directory.

Parameters:
directory - a RandomMediaDirectory value

enableDirectory

public void enableDirectory(String dirName)
Enables the named RandomMediaDirectory.

Parameters:
dirName - a String value

disableDirectory

public void disableDirectory(String dirName)
Disables the named RandomMediaDirectory.

Parameters:
dirName - a String value

clearDirectories

public void clearDirectories()
Removes all directories and clears any cache.


toggleEnabled

public void toggleEnabled(String dirName)
Toggles the enabled state of the named RandomMediaDirectory.


isDirectoryEnabled

public boolean isDirectoryEnabled(String dirName)
Returns whether the named directory is enabled or not.

Parameters:
dirName - a String value
Returns:
a boolean value

getNumberOfEnabledItems

public int getNumberOfEnabledItems()
Returns a count of items in enabled directories.

Returns:
an int value

getNumberOfTotalItems

public int getNumberOfTotalItems()
Returns a count of items in enabled and disabled directories.

Returns:
an int value

getNumberOfDisabledItems

public int getNumberOfDisabledItems()
Returns a count of items in disabled directories.

Returns:
an int value

getRandomURL

public URL getRandomURL()
Returns a random URL from one of the enabled directories.

Specified by:
getRandomURL in interface RandomURLProvider
Returns:
an URL value

getSubDirectoryNames

public String[] getSubDirectoryNames()
Returns a string array of subdirectory names.

Returns:
a String[] value

actionPerformed

public void actionPerformed(ActionEvent e)
Toggles the enabled state of a RandomMediaDirectory named by the ActionEvent's ActionCommand. This is useful when you have widgets such as CheckBoxes with media directory names.

Specified by:
actionPerformed in interface ActionListener
Parameters:
e - an ActionEvent value