Package ca.cgjennings.platform
Class DesktopIntegration
- java.lang.Object
-
- ca.cgjennings.platform.DesktopIntegration
-
public class DesktopIntegration extends java.lang.ObjectThis utility class implements essentially the same functionality as theDesktopAPI, with the following differences:- Its methods are static; there is no need to call a
Desktop.getDesktop()-type method to use it. - When a method is not supported, it simply does nothing instead of throwing an exception. There are public constants available to determine if an operation is supported beforehand.
- The edit and print actions will fall back to the open action if they are not supported but the open action is supported.
- You can optionally supply a UI component, in which case a wait cursor will be set for a few seconds to provide feedback that the operation is in progress.
- Additional desktop actions are available.
- Since:
- 3.0
- Author:
- Chris Jennings
- Its methods are static; there is no need to call a
-
-
Field Summary
Fields Modifier and Type Field Description static booleanBROWSE_SUPPORTEDThis istrueif thebrowse(java.net.URI)method is supported.static booleanEDIT_SUPPORTEDThis istrueif theopen(java.io.File)method is supported.static booleanMAIL_SUPPORTEDThis istrueif themail(java.net.URI)method is supported.static booleanOPEN_SUPPORTEDThis istrueif theopen(java.io.File)method is supported.static booleanPRINT_SUPPORTEDThis istrueif theopen(java.io.File)method is supported.static booleanSHOW_IN_SHELL_SUPPORTEDThis istrueif theshowInShell(java.io.File)method is supported.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidbrowse(java.lang.String url)Displays a Web page in the system browser.static voidbrowse(java.net.URI uri)Displays a Web page in the system browser.static voidbrowse(java.net.URI uri, java.awt.Component feedbackComponent)Displays a Web page in the system browser.static voidbrowse(java.net.URL url)Displays a Web page in the system browser.static voidedit(java.io.File file)Opens the specified file for editing using the default application on this system.static voidedit(java.io.File file, java.awt.Component feedbackComponent)Opens the specified file for editing using the default application on this system.static voidmail(java.net.URI uri)Opens the default mail application to send an email based on the specifiedmailtoURI.static voidmail(java.net.URI uri, java.awt.Component feedbackComponent)Opens the default mail application to send an email based on the specifiedmailtoURI.static voidopen(java.io.File file)Opens the specified file using the default application on this system.static voidopen(java.io.File file, java.awt.Component feedbackComponent)Opens the specified file using the default application on this system.static voidprint(java.io.File file)Prints the specified file using the default application on this system.static voidprint(java.io.File file, java.awt.Component feedbackComponent)Prints the specified file using the default application on this system.static booleanshowInShell(java.io.File f)Shows a specified file's icon in the graphical system shell.static booleanshowInShell(java.io.File f, java.awt.Component feedbackComponent)Shows a specified file's icon in the graphical system shell.
-
-
-
Field Detail
-
BROWSE_SUPPORTED
public static final boolean BROWSE_SUPPORTED
This istrueif thebrowse(java.net.URI)method is supported.
-
MAIL_SUPPORTED
public static final boolean MAIL_SUPPORTED
This istrueif themail(java.net.URI)method is supported.
-
OPEN_SUPPORTED
public static final boolean OPEN_SUPPORTED
This istrueif theopen(java.io.File)method is supported.
-
EDIT_SUPPORTED
public static final boolean EDIT_SUPPORTED
This istrueif theopen(java.io.File)method is supported.
-
PRINT_SUPPORTED
public static final boolean PRINT_SUPPORTED
This istrueif theopen(java.io.File)method is supported.
-
SHOW_IN_SHELL_SUPPORTED
public static final boolean SHOW_IN_SHELL_SUPPORTED
This istrueif theshowInShell(java.io.File)method is supported.
-
-
Method Detail
-
browse
public static void browse(java.net.URI uri) throws java.io.IOExceptionDisplays a Web page in the system browser.- Parameters:
uri- the URI to display- Throws:
java.io.IOException- if an I/O error occurs while starting the browser
-
browse
public static void browse(java.net.URI uri, java.awt.Component feedbackComponent) throws java.io.IOExceptionDisplays a Web page in the system browser.- Parameters:
uri- the URI to displayfeedbackComponent- an optional component used to display feedback- Throws:
java.io.IOException- if an I/O error occurs while starting the browser
-
browse
public static void browse(java.net.URL url) throws java.io.IOExceptionDisplays a Web page in the system browser. This is a convenience that accepts a URL object.- Parameters:
url- the location to open- Throws:
java.io.IOException- if an I/O error occurs while starting the browser or the URL is malformed
-
browse
public static void browse(java.lang.String url) throws java.io.IOExceptionDisplays a Web page in the system browser. This is a convenience that accepts a URL string.- Parameters:
url- the location to open- Throws:
java.io.IOException- if an I/O error occurs while starting the browser or the URL is malformed
-
mail
public static void mail(java.net.URI uri) throws java.io.IOExceptionOpens the default mail application to send an email based on the specifiedmailtoURI. If the URI isnull, opens the mail application to compose an email, but does not specify any details of the email.- Parameters:
uri- themailtoURI for the message- Throws:
java.io.IOException- if an I/O error occurs while starting the application
-
mail
public static void mail(java.net.URI uri, java.awt.Component feedbackComponent) throws java.io.IOExceptionOpens the default mail application to send an email based on the specifiedmailtoURI. If the URI isnull, opens the mail application to compose an email, but does not specify any details of the email.- Parameters:
uri-feedbackComponent- an optional component used to display feedback- Throws:
java.io.IOException- if an I/O error occurs while starting the application
-
open
public static void open(java.io.File file) throws java.io.IOExceptionOpens the specified file using the default application on this system.- Parameters:
file- the file to open- Throws:
java.io.IOException- if an I/O error occurs while starting the application
-
open
public static void open(java.io.File file, java.awt.Component feedbackComponent) throws java.io.IOExceptionOpens the specified file using the default application on this system.- Parameters:
file- the file to openfeedbackComponent- an optional component used to display feedback- Throws:
java.io.IOException- if an I/O error occurs while starting the application
-
edit
public static void edit(java.io.File file) throws java.io.IOExceptionOpens the specified file for editing using the default application on this system. On some platforms it may be possible to register different applications for editing versus opening a file, in which case opening the file would typically open some kind of preview application.If the underlying system does not support this feature, it will be
open(java.io.File)ed instead.- Parameters:
file- the file to open for editing- Throws:
java.io.IOException- if an I/O error occurs while starting the application
-
edit
public static void edit(java.io.File file, java.awt.Component feedbackComponent) throws java.io.IOExceptionOpens the specified file for editing using the default application on this system. On some platforms it may be possible to register different applications for editing versus opening a file, in which case opening the file would typically open some kind of preview application.If the underlying system does not support this feature, it will be
open(java.io.File)ed instead.- Parameters:
file- the file to open for editingfeedbackComponent- an optional component used to display feedback- Throws:
java.io.IOException- if an I/O error occurs while starting the application
-
print
public static void print(java.io.File file) throws java.io.IOExceptionPrints the specified file using the default application on this system.If the underlying system does not support this feature, it will be
open(java.io.File)ed instead.- Parameters:
file- the file to print- Throws:
java.io.IOException- if an I/O error occurs while starting the application
-
print
public static void print(java.io.File file, java.awt.Component feedbackComponent) throws java.io.IOExceptionPrints the specified file using the default application on this system.If the underlying system does not support this feature, it will be
open(java.io.File)ed instead.- Parameters:
file- the file to printfeedbackComponent- an optional component used to display feedback- Throws:
java.io.IOException- if an I/O error occurs while starting the application
-
showInShell
public static boolean showInShell(java.io.File f)
Shows a specified file's icon in the graphical system shell. If the file is a directory, that directory is displayed using the graphical shell (e.g., Explorer, Finder). If it is a file, then the parent directory is displayed using the shell. If supported by the host platform, the file will also be selected if possible. If there is an error such that the folder cannot be shown, this method returnsfalse.- Parameters:
f- the file to display and select- Returns:
falseif the folder could not be displayed
-
showInShell
public static boolean showInShell(java.io.File f, java.awt.Component feedbackComponent)Shows a specified file's icon in the graphical system shell. If the file is a directory, that directory is displayed using the graphical shell (e.g., Explorer, Finder). If it is a file, then the parent directory is displayed using the shell. If supported by the host platform, the file will also be selected if possible. If there is an error such that the folder cannot be shown, this method returnsfalse.- Parameters:
f- the file to display and selectfeedbackComponent- an optional component used to display feedback- Returns:
falseif the folder could not be displayed
-
-