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
static int MAC
          Indicates that the system is some variety of Apple Macintosh.
static int UNIX
          Indicates that the system is some variety of Unix or Linux.
static int UNKNOWN
          Indicates that the type of system cannot be determined.
static int WINDOWS
          Indicates that the system is some variety of Microsoft Windows.
 
Method Summary
static boolean areCollectionsAvailable()
          Checks whether the JDK 1.2 collection classes are available.
static boolean areStandardFontFamiliesAvailable()
          Checks whether the JDK 1.2 standard font families (Serif, SansSerif, and Monospaced) are available.
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.
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.
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.
static String getJTFVersion()
          Returns the version number of the JTF libraries as a string suitable for use with the compareVersion method.
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.
static boolean isJMFAvailable()
          Checks whether the Java Media Framework is available.
static boolean isMac()
          Checks whether the platform is a Macintosh.
static boolean isSunAudioAvailable()
          Checks whether the sun.audio package is available.
static boolean isSwingAvailable()
          Checks whether Swing is available.
static boolean isUnix()
          Checks whether the platform is Unix.
static boolean isWindows()
          Checks whether the platform is a Windows machine.
static void setFileTypeAndCreator(File file, String type, String creator)
          Sets the Macintosh file type and creator.
static void setFileTypeAndCreator(String filename, String type, String creator)
          Sets the Macintosh file type and creator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAC

public static final int MAC
Indicates that the system is some variety of Apple Macintosh.

See Also:
Constant Field Values

UNIX

public static final int UNIX
Indicates that the system is some variety of Unix or Linux.

See Also:
Constant Field Values

UNKNOWN

public static final int UNKNOWN
Indicates that the type of system cannot be determined.

See Also:
Constant Field Values

WINDOWS

public static final int WINDOWS
Indicates that the system is some variety of Microsoft Windows.

See Also:
Constant Field Values
Method Detail

areCollectionsAvailable

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.

Returns:
true if collections are available, false otherwise

areStandardFontFamiliesAvailable

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

Returns:
true if the standard fonts are available, false otherwise

compareVersion

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) . . .
 

Parameters:
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

compareVersion

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.

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

copyFileTypeAndCreator

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.

Parameters:
oldFile - The File object corresponding to the existing file
newFile - The File object corresponding to the new file

getJTFVersion

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.

Returns:
The loaded version of the JTF libraries

getPlatform

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.

Returns:
A constant specifying the platform type

isJMFAvailable

public static boolean isJMFAvailable()
Checks whether the Java Media Framework is available.

Returns:
true if the JMF package is available, false otherwise

isMac

public static boolean isMac()
Checks whether the platform is a Macintosh.

Returns:
true if the platform is a Macintosh, false otherwise

isSunAudioAvailable

public static boolean isSunAudioAvailable()
Checks whether the sun.audio package is available.

Returns:
true if the sun.audio package is available, false otherwise

isSwingAvailable

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.

Returns:
true if Swing is available, false otherwise

isUnix

public static boolean isUnix()
Checks whether the platform is Unix.

Returns:
true if the platform is Unix, false otherwise

isWindows

public static boolean isWindows()
Checks whether the platform is a Windows machine.

Returns:
true if the platform is a Windows machine, false otherwise

setFileTypeAndCreator

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.

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

setFileTypeAndCreator

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.

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