acm.util
Class Platform

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

public class Platform
extends Object

This class contains methods to support platform-specific code.


Field Summary
int MAC
Indicates that the system is some variety of Apple Macintosh.
int UNIX
Indicates that the system is some variety of Unix or Linux.
int UNKNOWN
Indicates that the type of system cannot be determined.
int WINDOWS
Indicates that the system is some variety of Microsoft Windows.
 
Method Summary
boolean areCollectionsAvailable()
Checks whether the JDK 1.2 collection classes are available.
boolean areStandardFontFamiliesAvailable()
Checks whether the JDK 1.2 standard font families (Serif, SansSerif, and Monospaced) are available.
int compareVersion(String version)
This method compares the Java version given in the system properties with the specified version and returns -1, 0, or +1 depending on whether the system version is earlier than, equal to, or later than the specified one.
int compareVersion(String v1, String v2)
This method compares the version strings v1 and v2 and returns -1, 0, or +1 depending on whether v1 is earlier than, equal to, or later than v2.
void copyFileTypeAndCreator(File oldFile, File newFile)
Sets the Macintosh file type and creator for the new file using the old file as a model.
String getJTFVersion()
Returns the version number of the JTF libraries as a string suitable for use with the compareVersion method.
int getPlatform()
Returns an enumeration constant specifying the type of platform on which this applet is running, which is one of the supported types defined at the beginning of this class.
boolean isJMFAvailable()
Checks whether the Java Media Framework is available.
boolean isMac()
Checks whether the platform is a Macintosh.
boolean isSunAudioAvailable()
Checks whether the sun.audio package is available.
boolean isSwingAvailable()
Checks whether Swing is available.
boolean isUnix()
Checks whether the platform is Unix.
boolean isWindows()
Checks whether the platform is a Windows machine.
void setFileTypeAndCreator(File file, String type, String creator)
Sets the Macintosh file type and creator.
void setFileTypeAndCreator(String filename, String type, String creator)
Sets the Macintosh file type and creator.
 

Field Detail

public static final int MAC

Indicates that the system is some variety of Apple Macintosh.

See Also:
Constant Field Values

public static final int UNIX

Indicates that the system is some variety of Unix or Linux.

See Also:
Constant Field Values

public static final int UNKNOWN

Indicates that the type of system cannot be determined.

See Also:
Constant Field Values

public static final int WINDOWS

Indicates that the system is some variety of Microsoft Windows.

See Also:
Constant Field Values
Method Detail

public static boolean areCollectionsAvailable()

Checks whether the JDK 1.2 collection classes are available. Some browsers return a version of the JDK that does not actually match what is supported. This method actually checks whether the collection classes are there by looking for the ArrayList class.

 
Usage: if (Platform.areCollectionsAvailable()) . . . 
Returns: true if collections are available, false otherwise
 


public static boolean areStandardFontFamiliesAvailable()

Checks whether the JDK 1.2 standard font families (Serif, SansSerif, and Monospaced) are available.

 
Usage: if (Platform.areStandardFontFamiliesAvailable()) . . . 
Returns: true if the standard fonts are available, false otherwise
 


public static int compareVersion(String version)

This method compares the Java version given in the system properties with the specified version and returns -1, 0, or +1 depending on whether the system version is earlier than, equal to, or later than the specified one. Thus, to test whether the current version of the JDK was at least 1.2.1, for example, you could write


      if (Platform.compareVersion("1.2.1") >= 0) . . .
 

 
Usage: int cmp = Platform.compareVersion(version); 
Parameter: 
version  A string consisting of integers separated by periods
Returns: -1, 0, or +1 depending on whether the system version is earlier than, equal to, or later than the specified one
 


public static int compareVersion(String v1, String v2)

This method compares the version strings v1 and v2 and returns -1, 0, or +1 depending on whether v1 is earlier than, equal to, or later than v2.

 
Usage: int cmp = Platform.compareVersion(v1, v2); 
Parameters: 
v1  A string consisting of integers separated by periods
v2  A second version string in the same format
Returns: -1, 0, or +1 depending on whether v1 is earlier than, equal to, or later than v2
 


public static void copyFileTypeAndCreator(File oldFile, File newFile)

Sets the Macintosh file type and creator for the new file using the old file as a model. This method is ignored on non-Mac platforms.

 
Usage: Platform.copyFileTypeAndCreator(oldFile, newFile); 
Parameters: 
oldFile  The File object corresponding to the existing file
newFile  The File object corresponding to the new file
 


public static String getJTFVersion()

Returns the version number of the JTF libraries as a string suitable for use with the compareVersion method. Note that this returns the value of the version of the library that is actually loaded. Making this a constant would mean that the value would be the one with which the code was compiled, which is less likely to be useful.

 
Usage: String version = getJTFVersion(); 
Returns: The loaded version of the JTF libraries
 


public static int getPlatform()

Returns an enumeration constant specifying the type of platform on which this applet is running, which is one of the supported types defined at the beginning of this class.

 
Usage: int platform = Platform.getPlatform(); 
Returns: A constant specifying the platform type
 


public static boolean isJMFAvailable()

Checks whether the Java Media Framework is available.

 
Usage: if (Platform.isJMFAvailable()) . . . 
Returns: true if the JMF package is available, false otherwise
 


public static boolean isMac()

Checks whether the platform is a Macintosh.

 
Usage: if (Platform.isMac()) . . . 
Returns: true if the platform is a Macintosh, false otherwise
 


public static boolean isSunAudioAvailable()

Checks whether the sun.audio package is available.

 
Usage: if (Platform.isSunAudioAvailable()) . . . 
Returns: true if the sun.audio package is available, false otherwise
 


public static boolean isSwingAvailable()

Checks whether Swing is available. Unfortunately, some browsers seem to lie about the JDK version and return a 1.2 number without actually having Swing. This implementation tests the version first, but then confirms the result by looking for the JComponent class. Checking the version first means that no SecurityExceptions will be logged in Windows machines, which always log SecurityExceptions, even if the exception is caught.

 
Usage: if (Platform.isSwingAvailable()) . . . 
Returns: true if Swing is available, false otherwise
 


public static boolean isUnix()

Checks whether the platform is Unix.

 
Usage: if (Platform.isUnix()) . . . 
Returns: true if the platform is Unix, false otherwise
 


public static boolean isWindows()

Checks whether the platform is a Windows machine.

 
Usage: if (Platform.isWindows()) . . . 
Returns: true if the platform is a Windows machine, false otherwise
 


public static void setFileTypeAndCreator(File file, String type, String creator)

Sets the Macintosh file type and creator. This method is ignored on non-Mac platforms.

 
Usage: Platform.setFileTypeAndCreator(file, type, creator); 
Parameters: 
file  The File object corresponding to the file
type  A four-character string indicating the file type
creator  A four-character string indicating the file type
 


public static void setFileTypeAndCreator(String filename, String type, String creator)

Sets the Macintosh file type and creator. This method is ignored on non-Mac platforms.

 
Usage: Platform.setFileTypeAndCreator(filename, type, creator); 
Parameters: 
filename  The name of the file
type  A four-character string indicating the file type
creator  A four-character string indicating the file type