Java Doc for Desktop.java in  » 6.0-JDK-Core » AWT » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.awt.Desktop

Desktop
public class Desktop (Code)
The Desktop class allows a Java application to launch associated applications registered on the native desktop to handle a java.net.URI or a file.

Supported operations include:

  • launching the user-default browser to show a specified URI;
  • launching the user-default mail client with an optional mailto URI;
  • launching a registered application to open, edit or print a specified file.

This class provides methods corresponding to these operations. The methods look for the associated application registered on the current platform, and launch it to handle a URI or file. If there is no associated application or the associated application fails to be launched, an exception is thrown.

An application is registered to a URI or file type; for example, the "sxi" file extension is typically registered to StarOffice. The mechanism of registering, accessing, and launching the associated application is platform-dependent.

Each operation is an action type represented by the Desktop.Action class.

Note: when some action is invoked and the associated application is executed, it will be executed on the same system as the one on which the Java application was launched.
since:
   1.6
author:
   Armin Chen
author:
   George Zhang


Inner Class :public static enum Action



Method Summary
public  voidbrowse(URI uri)
     Launches the default browser to display a URI . If the default browser is not able to handle the specified URI , the application registered for handling URIs of the specified type is invoked.
public  voidedit(File file)
     Launches the associated editor application and opens a file for editing.
public static synchronized  DesktopgetDesktop()
     Returns the Desktop instance of the current browser context.
public static  booleanisDesktopSupported()
     Tests whether this class is supported on the current platform.
public  booleanisSupported(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.

public  voidmail()
     Launches the mail composing window of the user default mail client.
public  voidmail(URI mailtoURI)
     Launches the mail composing window of the user default mail client, filling the message fields specified by a mailto: URI.

A mailto: URI can specify message fields including "to", "cc", "subject", "body", etc.

public  voidopen(File file)
     Launches the associated application to open the file.
public  voidprint(File file)
     Prints a file with the native desktop printing facility, using the associated application's print command.



Method Detail
browse
public void browse(URI uri) throws IOException(Code)
Launches the default browser to display a URI . If the default browser is not able to handle the specified URI , the application registered for handling URIs of the specified type is invoked. The application is determined from the protocol and path of the URI , as defined by the URI class.

If the calling thread does not have the necessary permissions, and this is invoked from within an applet, 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, BasicService.showDocument() is used.
Parameters:
  uri - the URI to be displayed in the user default browser
throws:
  NullPointerException - if uri is null
throws:
  UnsupportedOperationException - if the current platformdoes not support the Desktop.Action.BROWSE action
throws:
  IOException - if the user default browser is not found,or it fails to be launched, or the default handler applicationfailed to be launched
throws:
  SecurityException - if a security manager exists and itdenies theAWTPermission("showWindowWithoutWarningBanner")permission, or the calling thread is not allowed to create asubprocess; and not invoked from within an applet or Java Web Startedapplication
throws:
  IllegalArgumentException - if the necessary permissionsare not available and the URI can not be converted to a URL
See Also:   java.net.URI
See Also:   java.awt.AWTPermission
See Also:   java.applet.AppletContext




edit
public void edit(File file) throws IOException(Code)
Launches the associated editor application and opens a file for editing.
Parameters:
  file - the file to be opened for editing
throws:
  NullPointerException - if the specified file is null
throws:
  IllegalArgumentException - if the specified file doesn'texist
throws:
  UnsupportedOperationException - if the current platformdoes not support the Desktop.Action.EDIT action
throws:
  IOException - if the specified file has no associatededitor, or the associated application fails to be launched
throws:
  SecurityException - if a security manager exists and itsjava.lang.SecurityManager.checkRead(java.lang.String)method denies read access to the file, or java.lang.SecurityManager.checkWrite(java.lang.String) methoddenies write access to the file, or it denies theAWTPermission("showWindowWithoutWarningBanner")permission, or the calling thread is not allowed to create asubprocess
See Also:   java.awt.AWTPermission



getDesktop
public static synchronized Desktop getDesktop()(Code)
Returns the Desktop instance of the current browser context. On some platforms the Desktop API may not be supported; use the Desktop.isDesktopSupported method to determine if the current desktop is supported. the Desktop instance of the current browser context
throws:
  HeadlessException - if GraphicsEnvironment.isHeadless returns true
throws:
  UnsupportedOperationException - if this class is notsupported on the current platform
See Also:   Desktop.isDesktopSupported()
See Also:   java.awt.GraphicsEnvironment.isHeadless



isDesktopSupported
public static boolean isDesktopSupported()(Code)
Tests whether this class is supported on the current platform. If it's supported, use Desktop.getDesktop() to retrieve an instance. true if this class is supported on thecurrent platform; false otherwise
See Also:   Desktop.getDesktop()



isSupported
public boolean isSupported(Action action)(Code)
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 Desktop.Action.OPEN action. But for a specific file, there may not be an application registered to open it. In this case, Desktop.isSupported may return true , but the corresponding action method will throw an IOException .
Parameters:
  action - the specified Action true if the specified action is supported onthe current platform; false otherwise
See Also:   Desktop.Action




mail
public void mail() throws IOException(Code)
Launches the mail composing window of the user default mail client.
throws:
  UnsupportedOperationException - if the current platformdoes not support the Desktop.Action.MAIL action
throws:
  IOException - if the user default mail client is notfound, or it fails to be launched
throws:
  SecurityException - if a security manager exists and itdenies theAWTPermission("showWindowWithoutWarningBanner")permission, or the calling thread is not allowed to create asubprocess
See Also:   java.awt.AWTPermission



mail
public void mail(URI mailtoURI) throws IOException(Code)
Launches the mail composing window of the user default mail client, filling the message fields specified by a mailto: URI.

A mailto: URI can specify message fields including "to", "cc", "subject", "body", etc. See The mailto URL scheme (RFC 2368) for the mailto: URI specification details.
Parameters:
  mailtoURI - the specified mailto: URI
throws:
  NullPointerException - if the specified URI is null
throws:
  IllegalArgumentException - if the URI scheme is not"mailto"
throws:
  UnsupportedOperationException - if the current platformdoes not support the Desktop.Action.MAIL action
throws:
  IOException - if the user default mail client is notfound or fails to be launched
throws:
  SecurityException - if a security manager exists and itdenies theAWTPermission("showWindowWithoutWarningBanner")permission, or the calling thread is not allowed to create asubprocess
See Also:   java.net.URI
See Also:   java.awt.AWTPermission




open
public void open(File file) throws IOException(Code)
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.
Parameters:
  file - the file to be opened with the associated application
throws:
  NullPointerException - if file is null
throws:
  IllegalArgumentException - if the specified file doesn'texist
throws:
  UnsupportedOperationException - if the current platformdoes not support the Desktop.Action.OPEN action
throws:
  IOException - if the specified file has no associatedapplication or the associated application fails to be launched
throws:
  SecurityException - if a security manager exists and itsjava.lang.SecurityManager.checkRead(java.lang.String)method denies read access to the file, or it denies theAWTPermission("showWindowWithoutWarningBanner")permission, or the calling thread is not allowed to create asubprocess
See Also:   java.awt.AWTPermission




print
public void print(File file) throws IOException(Code)
Prints a file with the native desktop printing facility, using the associated application's print command.
Parameters:
  file - the file to be printed
throws:
  NullPointerException - if the specified file is null
throws:
  IllegalArgumentException - if the specified file doesn'texist
throws:
  UnsupportedOperationException - if the current platformdoes not support the Desktop.Action.PRINT action
throws:
  IOException - if the specified file has no associatedapplication that can be used to print it
throws:
  SecurityException - if a security manager exists and itsjava.lang.SecurityManager.checkRead(java.lang.String)method denies read access to the file, or its java.lang.SecurityManager.checkPrintJobAccess method deniesthe permission to print the file, or the calling thread is notallowed to create a subprocess



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.