acm.util
Class JTFTools

java.lang.Object
  extended by acm.util.JTFTools

public class JTFTools
extends Object

This class provides a collection of static utility methods that are used elsewhere in the ACM packages.


Method Summary
void copyBytes(InputStream in, OutputStream out, long nBytes)
Copies the specified number bytes from the input stream to the output stream.
void copyFile(File oldFile, File newFile)
Copies a file from oldFile to newFile.
Container createEmptyContainer()
Returns an empty lightweight container.
Color decodeColor(String name)
Decodes a color name.
Font decodeFont(String str)
Decodes a font in the style of Font.decode.
Font decodeFont(String str, Font oldFont)
Decodes a font in the style of Font.decode.
String findFontFamily(String str)
Finds the first font family in the string str that exists in the current GraphicsEnvironment.
Frame getEnclosingFrame(Component comp)
Returns the frame that encloses the specified component.
String[] getFontList()
Returns an array of the available font family names.
Font getStandardFont(Font font)
Returns a font that will approximate the specified font in this environment.
boolean matchFilenamePattern(String filename, String pattern)
Determines whether the filename matches the specified pattern.
void pause(double milliseconds)
Delays the calling thread for the specified time, which is expressed in milliseconds.
 

Method Detail

public static void copyBytes(InputStream in, OutputStream out, long nBytes) throws IOException

Copies the specified number bytes from the input stream to the output stream.

 
Parameters: 
in  The input stream
out  The output stream
nBytes  The number of bytes to copy
 

Throws:
IOException

public static void copyFile(File oldFile, File newFile)

Copies a file from oldFile to newFile.

 
Usage: JTFTools.copyFile(oldFile, newFile); 
Parameters: 
oldFile  A File object indicating the existing file
newFile  A File object indicating the new file
 


public static Container createEmptyContainer()

Returns an empty lightweight container. Several packages need to create such components as placeholders. Defining it in JTFTools gives those pacakges access to a common mechanism.

 
Usage: Container comp = JTFTools.createEmptyContainer(); 
Returns: An empty lightweight container that can be used as a placeholder
 


public static Color decodeColor(String name)

Decodes a color name. This method is similar to Color.decode except in that it allows named colors and system colors.

 
Usage: color = JTFTools.decodeColor(name); 
Parameter: 
name  The string name of the color
Returns: The color corresponding to the specified name
 


public static Font decodeFont(String str)

Decodes a font in the style of Font.decode.

 
Usage: Font font = JTFTools.decodeFont(str); 
Parameter: 
str  The string to decode
Returns: The new font
 


public static Font decodeFont(String str, Font oldFont)

Decodes a font in the style of Font.decode. The only difference is that this method takes a font parameter that gives default values for the different parts of the font. If the family, size, or style is specified as an asterisk, the corresponding value is taken from the supplied font.

 
Usage: Font font = JTFTools.decodeFont(str, oldFont); 
Parameters: 
str  The string to decode
oldFont  The font whose properties are used as defaults
Returns: The new font
 


public static String findFontFamily(String str)

Finds the first font family in the string str that exists in the current GraphicsEnvironment. As in HTML font tags, the str consists of a set of font names separated by semicolons. The findFontFamily method returns the first family name that exists in the list of loaded fonts, or null if there are none.

 
Usage: String familyName = JTFTools.findFontFamily(str); 
Parameter: 
str  The list of family names separated by semicolons
Returns: The first family name that exists, or null if none
 


public static Frame getEnclosingFrame(Component comp)

Returns the frame that encloses the specified component.

 
Usage: Frame frame = JTFTools.getEnclosingFrame(comp); 
Parameter: 
comp  The component at which to start the search
Returns: The nearest enclosing Frame object
 


public static String[] getFontList()

Returns an array of the available font family names.

 
Usage: String[] fonts = JTFTools.getFontList(); 
Returns: An array of the available font family names
 


public static Font getStandardFont(Font font)

Returns a font that will approximate the specified font in this environment. This method is required because some browsers do not support the standard fonts Serif, SansSerif, and Monospaced.

 
Usage: Font newFont = JTFTools.getStandardFont(font); 
Parameter: 
font  The font being checked
Returns: The new font
 


public static boolean matchFilenamePattern(String filename, String pattern)

Determines whether the filename matches the specified pattern. The pattern string is interpreted in much the same way that a Unix shell expands filenames and supports the following wildcard options:
?Matches any single character
*Matches any sequence of characters
[...]Matches any of the specified characters
[^...]Matches any character except the specified ones
The last two options allow a range of characters to be specified in the form a-z.

 
Usage: if (JTFTools.matchFilenamePattern(filename, pattern)) . . . 
Parameters: 
filename  The filename being tested
pattern  The pattern including wildcards
Returns: true if the filename matches the pattern
 


public static void pause(double milliseconds)

Delays the calling thread for the specified time, which is expressed in milliseconds. Unlike Thread.sleep, this method never throws an exception.

 
Usage: JTFTools.pause(milliseconds); 
Parameter: 
milliseconds  The sleep time in milliseconds