Methods Summary |
---|
public void | browse(java.net.URI uri)Launches the default browser to display a {@code URI}.
If the default browser is not able to handle the specified
{@code URI}, the application registered for handling
{@code URIs} of the specified type is invoked. The application
is determined from the protocol and path of the {@code URI}, as
defined by the {@code URI} class.
If the calling thread does not have the necessary permissions,
and this is invoked from within an applet,
{@code AppletContext.showDocument()} is used. Similarly, if the calling
does not have the necessary permissions, and this is invoked from within
a Java Web Started application, {@code BasicService.showDocument()}
is used.
SecurityException securityException = null;
try {
checkAWTPermission();
checkExec();
} catch (SecurityException e) {
securityException = e;
}
checkActionSupport(Action.BROWSE);
if (uri == null) {
throw new NullPointerException();
}
if (securityException == null) {
peer.browse(uri);
return;
}
// Calling thread doesn't have necessary priviledges.
// Delegate to DesktopBrowse so that it can work in
// applet/webstart.
URL url = null;
try {
url = uri.toURL();
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Unable to convert URI to URL", e);
}
sun.awt.DesktopBrowse db = sun.awt.DesktopBrowse.getInstance();
if (db == null) {
// Not in webstart/applet, throw the exception.
throw securityException;
}
db.browse(url);
|
private void | checkAWTPermission()Calls to the security manager's checkPermission method with
an AWTPermission("showWindowWithoutWarningBanner")
permission.
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new AWTPermission(
"showWindowWithoutWarningBanner"));
}
|
private void | checkActionSupport(java.awt.Desktop$Action actionType)Checks if the action type is supported.
if (!isSupported(actionType)) {
throw new UnsupportedOperationException("The " + actionType.name()
+ " action is not supported on the current platform!");
}
|
private void | checkExec()
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new FilePermission("<<ALL FILES>>",
SecurityConstants.FILE_EXECUTE_ACTION));
}
|
private static void | checkFileValidation(java.io.File file)Checks if the file is a valid file and readable.
if (file == null) throw new NullPointerException("File must not be null");
if (!file.exists()) {
throw new IllegalArgumentException("The file: "
+ file.getPath() + " doesn't exist.");
}
file.canRead();
|
public void | edit(java.io.File file)Launches the associated editor application and opens a file for
editing.
checkAWTPermission();
checkExec();
checkActionSupport(Action.EDIT);
file.canWrite();
checkFileValidation(file);
peer.edit(file);
|
public static synchronized java.awt.Desktop | getDesktop()Returns the Desktop instance of the current
browser context. On some platforms the Desktop API may not be
supported; use the {@link #isDesktopSupported} method to
determine if the current desktop is supported.
if (GraphicsEnvironment.isHeadless()) throw new HeadlessException();
if (!Desktop.isDesktopSupported()) {
throw new UnsupportedOperationException("Desktop API is not " +
"supported on the current platform");
}
sun.awt.AppContext context = sun.awt.AppContext.getAppContext();
Desktop desktop = (Desktop)context.get(Desktop.class);
if (desktop == null) {
desktop = new Desktop();
context.put(Desktop.class, desktop);
}
return desktop;
|
public static boolean | isDesktopSupported()Tests whether this class is supported on the current platform.
If it's supported, use {@link #getDesktop()} to retrieve an
instance.
Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
if (defaultToolkit instanceof SunToolkit) {
return ((SunToolkit)defaultToolkit).isDesktopSupported();
}
return false;
|
public boolean | isSupported(java.awt.Desktop$Action action)Tests whether an action is supported on the current platform.
Even when the platform supports an action, a file or URI may
not have a registered application for the action. For example,
most of the platforms support the {@link Desktop.Action#OPEN}
action. But for a specific file, there may not be an
application registered to open it. In this case, {@link
#isSupported} may return {@code true}, but the corresponding
action method will throw an {@link IOException}.
return peer.isSupported(action);
|
public void | mail()Launches the mail composing window of the user default mail
client.
checkAWTPermission();
checkExec();
checkActionSupport(Action.MAIL);
URI mailtoURI = null;
try{
mailtoURI = new URI("mailto:?");
peer.mail(mailtoURI);
} catch (URISyntaxException e){
// won't reach here.
}
|
public void | mail(java.net.URI mailtoURI)Launches the mail composing window of the user default mail
client, filling the message fields specified by a {@code
mailto:} URI.
A mailto: URI can specify message fields
including "to", "cc", "subject",
"body", etc. See The mailto URL
scheme (RFC 2368) for the {@code mailto:} URI specification
details.
checkAWTPermission();
checkExec();
checkActionSupport(Action.MAIL);
if (mailtoURI == null) throw new NullPointerException();
if (!"mailto".equalsIgnoreCase(mailtoURI.getScheme())) {
throw new IllegalArgumentException("URI scheme is not \"mailto\"");
}
peer.mail(mailtoURI);
|
public void | open(java.io.File file)Launches the associated application to open the file.
If the specified file is a directory, the file manager of
the current platform is launched to open it.
checkAWTPermission();
checkExec();
checkActionSupport(Action.OPEN);
checkFileValidation(file);
peer.open(file);
|
public void | print(java.io.File file)Prints a file with the native desktop printing facility, using
the associated application's print command.
checkExec();
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPrintJobAccess();
}
checkActionSupport(Action.PRINT);
checkFileValidation(file);
peer.print(file);
|