Class DesktopIntegration


  • public class DesktopIntegration
    extends java.lang.Object
    This utility class implements essentially the same functionality as the Desktop API, with the following differences:
    1. Its methods are static; there is no need to call a Desktop.getDesktop()-type method to use it.
    2. 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.
    3. The edit and print actions will fall back to the open action if they are not supported but the open action is supported.
    4. 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.
    5. Additional desktop actions are available.
    Since:
    3.0
    Author:
    Chris Jennings
    • 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 specified mailto URI.
      static void mail​(java.net.URI uri, java.awt.Component feedbackComponent)
      Opens the default mail application to send an email based on the specified mailto 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BROWSE_SUPPORTED

        public static final boolean BROWSE_SUPPORTED
        This is true if the browse(java.net.URI) method is supported.
      • MAIL_SUPPORTED

        public static final boolean MAIL_SUPPORTED
        This is true if the mail(java.net.URI) method is supported.
      • OPEN_SUPPORTED

        public static final boolean OPEN_SUPPORTED
        This is true if the open(java.io.File) method is supported.
      • EDIT_SUPPORTED

        public static final boolean EDIT_SUPPORTED
        This is true if the open(java.io.File) method is supported.
      • PRINT_SUPPORTED

        public static final boolean PRINT_SUPPORTED
        This is true if the open(java.io.File) method is supported.
      • SHOW_IN_SHELL_SUPPORTED

        public static final boolean SHOW_IN_SHELL_SUPPORTED
        This is true if the showInShell(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 display
        feedbackComponent - 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 specified mailto URI. If the URI is null, opens the mail application to compose an email, but does not specify any details of the email.
        Parameters:
        uri - the mailto 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 specified mailto URI. If the URI is null, 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 open
        feedbackComponent - 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 editing
        feedbackComponent - 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 print
        feedbackComponent - 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 returns false.
        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 returns false.
        Parameters:
        f - the file to display and select
        feedbackComponent - an optional component used to display feedback
        Returns:
        false if the folder could not be displayed