net.sf.fmj.ejmf.toolkit.util
Class Utility

java.lang.Object
  extended by net.sf.fmj.ejmf.toolkit.util.Utility

public class Utility
extends java.lang.Object

Static utilites for common JMF routines From the book: Essential JMF, Gordon, Talley (ISBN 0130801046). Used with permission.

Author:
Steve Talley & Rob Gordon

Constructor Summary
Utility()
           
 
Method Summary
static MediaLocator appArgToMediaLocator(java.lang.String arg)
          Converts a string to a URL.
static MediaLocator appletArgToMediaLocator(java.applet.Applet applet, java.lang.String arg)
          Converts an applet argument to a MediaLocator.
static javax.swing.Icon createDisabledIcon(javax.swing.ImageIcon imageIcon)
          Create a disabled icon using a gray filter.
static java.net.URL fileToURL(java.lang.String fileName)
          Convert a File to a URL using file: protocol.
static java.lang.String getExtension(java.io.File f)
          Given a File object, return a String representing the file's extension.
static java.lang.String getExtension(java.lang.String filename)
          Given a String representing a file name, return a String representing the file's extension.
static Time getMaximumLatency(Controller[] controllers)
          Given an array of Controllers, calculate the maximum startup latency in seconds.
static int pickAMaster(Player[] players)
          Pick a master Player for an array of Players.
static void showControls(Controller controller)
          Displays each Control not currently being shown.
static java.lang.String stateToString(int state)
          Convert a Controller state to a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utility

public Utility()
Method Detail

appletArgToMediaLocator

public static MediaLocator appletArgToMediaLocator(java.applet.Applet applet,
                                                   java.lang.String arg)
Converts an applet argument to a MediaLocator.

Returns:
A MediaLocator for the given argument.

fileToURL

public static java.net.URL fileToURL(java.lang.String fileName)
                              throws java.io.IOException,
                                     java.net.MalformedURLException
Convert a File to a URL using file: protocol.

Parameters:
fileName - The file to convert
Returns:
a java.net.URL representing file named by input File argument.
Throws:
java.io.IOException
java.net.MalformedURLException

appArgToMediaLocator

public static MediaLocator appArgToMediaLocator(java.lang.String arg)
Converts a string to a URL. Tries first to convert the string itself to a URL. If not successful, assumes arg is a file and tries to create a file URL using the full path name of the specified file. The return value of this routine should be checked to ensure that a URL was successfully created.

Parameters:
arg - the url string to convert
Returns:
a URL if successful, null otherwise

stateToString

public static java.lang.String stateToString(int state)
Convert a Controller state to a string

Parameters:
state - the state to convert
Returns:
a String representing the given state

getMaximumLatency

public static Time getMaximumLatency(Controller[] controllers)
Given an array of Controllers, calculate the maximum startup latency in seconds. If a Controller reports LATENCY_UNKNOWN, its value is ignored.

All Controllers must be at least in the Realized state. If a Controller is not in the realized state, its value is ignored.

If all Controllers report LATENCY_UNKNOWN, return LATENCY_UNKNOWN and let the caller worry about what to do.

Parameters:
controllers - An array of javax.media.Controller objects all at least realized.

Returns:
javax.media.Time object representing the maximum startup latency across all the input Controllers.

getExtension

public static java.lang.String getExtension(java.io.File f)
Given a File object, return a String representing the file's extension. If there is no extension, return null.

Parameters:
f - A java.io.File object
Returns:
A String representing file extension

getExtension

public static java.lang.String getExtension(java.lang.String filename)
Given a String representing a file name, return a String representing the file's extension. If there is no extension, return null.

Parameters:
filename - A filename as a java.lang.String object
Returns:
A String representing file extension

showControls

public static void showControls(Controller controller)
Displays each Control not currently being shown.


pickAMaster

public static int pickAMaster(Player[] players)
Pick a master Player for an array of Players. Return first Player that has a gain control. If no Player has a gain control, return 0. All the input Players are assumed to be realized, else they will return a null gain control.

Parameters:
players - an array of Players
Returns:
an index into the Player array of the Player chosen as the master Player.

createDisabledIcon

public static javax.swing.Icon createDisabledIcon(javax.swing.ImageIcon imageIcon)
Create a disabled icon using a gray filter.