|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object acm.util.MediaTools
public class MediaTools
This class implements a standard mechanism for loading images, sounds, and data files from the resources associated with a jar file.
Field Summary | |
---|---|
static String |
DEFAULT_AUDIO_PATH
The list of directories scanned for audio clips, separated by colons. |
static String |
DEFAULT_DATAFILE_PATH
The list of directories scanned for data files, separated by colons. |
static String |
DEFAULT_IMAGE_PATH
The list of directories scanned for images, separated by colons. |
Method Summary | |
---|---|
static void |
beep()
This method sounds the audible alert on the console, which is typically a beep sound. |
static AudioClip |
createAudioClip(InputStream in)
Generates an audio clip from an input stream containing the data bytes for the audio clip. |
static AudioClip |
createAudioClip(String[] hexData)
Generates an audio clip from a string array that provides the sound values. |
static BufferedImage |
createBufferedImage(Image image,
int type)
Creates a BufferedImage from the specified image. |
static Image |
createImage(InputStream in)
Generates an image from an input stream containing the data bytes for the image formatted in image/gif format. |
static Image |
createImage(int[][] array)
Generates an image from a two-dimensional array of pixel values. |
static Image |
createImage(int[] pixels,
int width,
int height)
Generates an image from a single-dimensional array of pixel values. |
static Image |
createImage(String[] hexData)
Generates an image from a string array that provides the pixel values. |
static Image |
createPSPreviewImage(Image image,
String[] preview)
Creates a new image that combines an existing image with a PostScript preview represented as a string array. |
static void |
defineAudioClip(String name,
AudioClip clip)
Inserts the given clip into the audio clip table under the specified name. |
static void |
defineImage(String name,
Image image)
Inserts the given image into the image table under the specified name. |
static void |
flushAudioClip(String name)
Removes the audio clip with the given name from the cache, allowing it to be freed by the garbage collector. |
static void |
flushImage(String name)
Removes the image with the given name from the cache, allowing it to be freed by the garbage collector. |
static InputStream |
getHexInputStream(String[] hexData)
Returns an input stream whose bytes come from the string array hex ,
in which the elements consist of continuous bytes of hex data. |
static Component |
getImageObserver()
This method returns a new lightweight component suitable as an imageObserver . |
static int[][] |
getPixelArray(Image image)
Returns a two-dimensional array of the pixels in the image. |
static boolean |
isCachingEnabled()
This method returns the status of the flag that determins whether images and audio clips are cached internally by name, as described in setCachingEnabled . |
static AudioClip |
loadAudioClip(String name)
Searches the default audio clip search path for an audio clip with the specified name and then loads it to create an AudioClip . |
static AudioClip |
loadAudioClip(String name,
String path)
Searches for an audio clip with the given name and loads it to create an AudioClip . |
static AudioClip |
loadAudioClip(URL url)
Loads an audio clip from the specified URL. |
static AudioClip |
loadAudioClip(URL url,
boolean topLevel)
Loads an audio clip from the specified URL. |
static Image |
loadImage(Image image)
Makes sure that the image is fully loaded before returning. |
static Image |
loadImage(String name)
Searches the default image search path for an image with the specified name and then loads it to create an Image . |
static Image |
loadImage(String name,
String path)
Searches for an image with the given name and loads it to create an Image . |
static Image |
loadImage(URL url)
Loads an image from the specified URL. |
static Image |
loadImage(URL url,
boolean topLevel)
Loads an image from the specified URL. |
static InputStream |
openDataFile(String name)
Searches the default datafile search path for a file with the specified name and then opens it to create an InputStream . |
static InputStream |
openDataFile(String name,
String path)
Searches for a data file with the given name and opens it to create an InputStream . |
static InputStream |
openDataFile(URL url)
Opens the specified URL to create an InputStream . |
static InputStream |
openDataFile(URL url,
boolean topLevel)
Opens a data file using the specified URL. |
static void |
saveImage(Image image,
File file)
Saves an image to the specified file. |
static void |
saveImage(Image image,
String filename)
Saves an image to a file with the specified filename. |
static void |
setCachingEnabled(boolean flag)
This method sets an internal flag in the MediaTools package to indicate
whether images and audio clips are cached internally by name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_AUDIO_PATH
public static final String DEFAULT_DATAFILE_PATH
public static final String DEFAULT_IMAGE_PATH
Method Detail |
---|
public static void beep()
public static AudioClip createAudioClip(InputStream in)
SoundClip
object from the data. If that fails, it then backs up to the older strategy
of using the SunAudioClip
class.
in
- An input stream containing the data
AudioClip
objectpublic static AudioClip createAudioClip(String[] hexData)
hexData
- A hex string array representing an audio clip
AudioClip
objectpublic static BufferedImage createBufferedImage(Image image, int type)
BufferedImage
from the specified image. The
type
parameter is used to specify the image type, as
described in the BufferedImage
documentation.
image
- The original imagetype
- The type code used to describe the image modelA
- BufferedImage
containing the image datapublic static Image createImage(InputStream in)
in
- An input stream containing the data
Image
objectpublic static Image createImage(int[][] array)
array
- A two-dimensional array of int
s representing the pixels
Image
objectpublic static Image createImage(int[] pixels, int width, int height)
pixels
- An array of int
s representing the pixelswidth
- The width of the imageheight
- The height of the image
Image
objectpublic static Image createImage(String[] hexData)
hexData
- A hex string array representing a .gif value
Image
objectpublic static Image createPSPreviewImage(Image image, String[] preview)
"PSPreview"
property.
image
- The original imagepreview
- The corresponding PostScript preview
public static void defineAudioClip(String name, AudioClip clip)
name
- The name for the audio clipclip
- The audio clip to be stored in the tablepublic static void defineImage(String name, Image image)
name
- The name for the imageimage
- The image to be stored in the tablepublic static void flushAudioClip(String name)
name
- The name for the audio clippublic static void flushImage(String name)
name
- The name for the imagepublic static InputStream getHexInputStream(String[] hexData)
hex
,
in which the elements consist of continuous bytes of hex data.
hexData
- An array of strings specifying a byte stream coded in hex
public static Component getImageObserver()
imageObserver
.
imageObserver
.public static int[][] getPixelArray(Image image)
image
- The image
public static boolean isCachingEnabled()
setCachingEnabled
.
true
if caching by name is enabled, false
otherwise.public static AudioClip loadAudioClip(String name)
AudioClip
. The search process
consists of the following steps:
AudioClip
. If so, read the
audio clip from the resource file.
The second and third steps are repeated for each element of the audio clip search path, which consists of a list of directories separated by colons.
name
- The name of the audio clip
AudioClip
objectpublic static AudioClip loadAudioClip(String name, String path)
AudioClip
. Its operation is identical to the single-argument
loadAudioClip
call except
in that this version allows the client to specify the search path
explicitly.
name
- The name of the audio clippath
- A string of directories names separated by colons
AudioClip
objectpublic static AudioClip loadAudioClip(URL url)
url
- The url containing the audio clip
AudioClip
objectpublic static AudioClip loadAudioClip(URL url, boolean topLevel)
topLevel
flag
is false
if this is invoked internally.
public static Image loadImage(Image image)
image
- The Image
which may not yet be loaded
Image
after ensuring that it is fully loadedpublic static Image loadImage(String name)
Image
. The search process
consists of the following steps:
Image
. If so, read the image
from the resource file.
The second and third steps are repeated for each element of the image search path, which consists of a list of directories separated by colons.
Unlike the getImage
method in the Applet
class,
loadImage
waits for an image to be fully loaded before returning.
name
- The name of the image
Image
objectpublic static Image loadImage(String name, String path)
Image
. Its operation is identical to the single-argument
loadImage
call except
in that this version allows the client to specify the search path
explicitly.
name
- The name of the imagepath
- A string of directories names separated by colons
Image
objectpublic static Image loadImage(URL url)
url
- The url containing the image
Image
objectpublic static Image loadImage(URL url, boolean topLevel)
topLevel
flag
is false
if this is invoked internally.
public static InputStream openDataFile(String name)
InputStream
. The search process
consists of the following steps:
InputStream
open on that resource.
These steps are repeated for each element of the datafile search path, which consists of a list of directories separated by colons.
name
- The name of the input file
InputStream
open on the specified filepublic static InputStream openDataFile(String name, String path)
InputStream
. Its operation is identical to the single-argument
openDataFile
call except
in that this version allows the client to specify the search path
explicitly.
name
- The name of the audio clippath
- A string of directories names separated by colons
InputStream
open on the specified filepublic static InputStream openDataFile(URL url)
InputStream
.
url
- The URL of the data file
InputStream
open on the specified URLpublic static InputStream openDataFile(URL url, boolean topLevel)
topLevel
flag
is false
if this is invoked internally.
public static void saveImage(Image image, File file)
image
- The imagefile
- The File
to which the image is savedpublic static void saveImage(Image image, String filename)
image
- The imagefilename
- The name of the file to which the image is savedpublic static void setCachingEnabled(boolean flag)
MediaTools
package to indicate
whether images and audio clips are cached internally by name. This flag is disabled
by default.
flag
- true
to enable caching by name, false
to disable it.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |