Package org.eclipse.swt.program
Class Program
- java.lang.Object
-
- org.eclipse.swt.program.Program
-
public final class Program extends java.lang.Object
Instances of this class represent programs and their associated file extensions in the operating system.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object other)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.boolean
execute(java.lang.String fileName)
Executes the program with the file as the single argument in the operating system.static Program
findProgram(java.lang.String extension)
Finds the program that is associated with an extension.static java.lang.String[]
getExtensions()
Answer all program extensions in the operating system.ImageData
getImageData()
Returns the receiver's image data.java.lang.String
getName()
Returns the receiver's name.static Program[]
getPrograms()
Answers all available programs in the operating system.int
hashCode()
Returns an integer hash code for the receiver.static boolean
launch(java.lang.String fileName)
Launches the operating system executable associated with the file or URL (http:// or https://).static boolean
launch(java.lang.String fileName, java.lang.String workingDir)
Launches the operating system executable associated with the file or URL (http:// or https://).java.lang.String
toString()
Returns a string containing a concise, human-readable description of the receiver.
-
-
-
Method Detail
-
findProgram
public static Program findProgram(java.lang.String extension)
Finds the program that is associated with an extension. The extension may or may not begin with a '.'. Note that aDisplay
must already exist to guarantee that this method returns an appropriate result.- Parameters:
extension
- the program extension- Returns:
- the program or
null
- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT when extension is null
-
getImageData
public ImageData getImageData()
Returns the receiver's image data. This is the icon that is associated with the receiver in the operating system.- Returns:
- the image data for the program, may be null
-
getPrograms
public static Program[] getPrograms()
Answers all available programs in the operating system. Note that aDisplay
must already exist to guarantee that this method returns an appropriate result.- Returns:
- an array of programs
-
getExtensions
public static java.lang.String[] getExtensions()
Answer all program extensions in the operating system. Note that aDisplay
must already exist to guarantee that this method returns an appropriate result.- Returns:
- an array of extensions
-
launch
public static boolean launch(java.lang.String fileName)
Launches the operating system executable associated with the file or URL (http:// or https://). If the file is an executable then the executable is launched. Note that aDisplay
must already exist to guarantee that this method returns an appropriate result.- Parameters:
fileName
- the file or program name or URL (http:// or https://)- Returns:
true
if the file is launched, otherwisefalse
- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT when fileName is null
-
launch
public static boolean launch(java.lang.String fileName, java.lang.String workingDir)
Launches the operating system executable associated with the file or URL (http:// or https://). If the file is an executable then the executable is launched. The program is launched with the specified working directory only when theworkingDir
exists andfileName
is an executable. Note that aDisplay
must already exist to guarantee that this method returns an appropriate result.- Parameters:
fileName
- the file name or program name or URL (http:// or https://)workingDir
- the name of the working directory or null- Returns:
true
if the file is launched, otherwisefalse
- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT when fileName is null
- Since:
- 3.6
-
equals
public boolean equals(java.lang.Object other)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.- Overrides:
equals
in classjava.lang.Object
- Parameters:
other
- the object to compare with this object- Returns:
true
if the object is the same as this object andfalse
otherwise- See Also:
hashCode()
-
execute
public boolean execute(java.lang.String fileName)
Executes the program with the file as the single argument in the operating system. It is the responsibility of the programmer to ensure that the file contains valid data for this program.- Parameters:
fileName
- the file or program name- Returns:
true
if the file is launched, otherwisefalse
- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT when fileName is null
-
getName
public java.lang.String getName()
Returns the receiver's name. This is as short and descriptive a name as possible for the program. If the program has no descriptive name, this string may be the executable name, path or empty.- Returns:
- the name of the program
-
hashCode
public int hashCode()
Returns an integer hash code for the receiver. Any two objects that returntrue
when passed toequals
must return the same value for this method.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the receiver's hash
- See Also:
equals(Object)
-
toString
public java.lang.String toString()
Returns a string containing a concise, human-readable description of the receiver.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of the program
-
-