Package ca.cgjennings.platform
Class DesktopIntegration
- java.lang.Object
-
- ca.cgjennings.platform.DesktopIntegration
-
public class DesktopIntegration extends java.lang.Object
This utility class implements essentially the same functionality as theDesktop
API, 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 boolean
BROWSE_SUPPORTED
This istrue
if thebrowse(java.net.URI)
method is supported.static boolean
EDIT_SUPPORTED
This istrue
if theopen(java.io.File)
method is supported.static boolean
MAIL_SUPPORTED
This istrue
if themail(java.net.URI)
method is supported.static boolean
OPEN_SUPPORTED
This istrue
if theopen(java.io.File)
method is supported.static boolean
PRINT_SUPPORTED
This istrue
if theopen(java.io.File)
method is supported.static boolean
SHOW_IN_SHELL_SUPPORTED
This istrue
if theshowInShell(java.io.File)
method is supported.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
browse(java.lang.String url)
Displays a Web page in the system browser.static void
browse(java.net.URI uri)
Displays a Web page in the system browser.static void
browse(java.net.URI uri, java.awt.Component feedbackComponent)
Displays a Web page in the system browser.static void
browse(java.net.URL url)
Displays a Web page in the system browser.static void
edit(java.io.File file)
Opens the specified file for editing using the default application on this system.static void
edit(java.io.File file, java.awt.Component feedbackComponent)
Opens the specified file for editing using the default application on this system.static void
mail(java.net.URI uri)
Opens the default mail application to send an email based on the specifiedmailto
URI.static void
mail(java.net.URI uri, java.awt.Component feedbackComponent)
Opens the default mail application to send an email based on the specifiedmailto
URI.static void
open(java.io.File file)
Opens the specified file using the default application on this system.static void
open(java.io.File file, java.awt.Component feedbackComponent)
Opens the specified file using the default application on this system.static void
print(java.io.File file)
Prints the specified file using the default application on this system.static void
print(java.io.File file, java.awt.Component feedbackComponent)
Prints the specified file using the default application on this system.static boolean
showInShell(java.io.File f)
Shows a specified file's icon in the graphical system shell.static boolean
showInShell(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 istrue
if thebrowse(java.net.URI)
method is supported.
-
MAIL_SUPPORTED
public static final boolean MAIL_SUPPORTED
This istrue
if themail(java.net.URI)
method is supported.
-
OPEN_SUPPORTED
public static final boolean OPEN_SUPPORTED
This istrue
if theopen(java.io.File)
method is supported.
-
EDIT_SUPPORTED
public static final boolean EDIT_SUPPORTED
This istrue
if theopen(java.io.File)
method is supported.
-
PRINT_SUPPORTED
public static final boolean PRINT_SUPPORTED
This istrue
if theopen(java.io.File)
method is supported.
-
SHOW_IN_SHELL_SUPPORTED
public static final boolean SHOW_IN_SHELL_SUPPORTED
This istrue
if theshowInShell(java.io.File)
method is supported.
-
-
Method Detail
-
browse
public static void browse(java.net.URI uri) throws java.io.IOException
Displays 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.IOException
Displays 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.IOException
Displays 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.IOException
Displays 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.IOException
Opens the default mail application to send an email based on the specifiedmailto
URI. If the URI isnull
, opens the mail application to compose an email, but does not specify any details of the email.- Parameters:
uri
- themailto
URI 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.IOException
Opens the default mail application to send an email based on the specifiedmailto
URI. 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.IOException
Opens 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.IOException
Opens 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.IOException
Opens 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.IOException
Opens 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.IOException
Prints 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.IOException
Prints 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:
false
if 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:
false
if the folder could not be displayed
-
-