Class DesktopUtils

java.lang.Object
org.pepsoft.util.DesktopUtils

public final class DesktopUtils extends Object
Utility methods for integrating into desktop environments. These methods do very little error checking and assume they are running on a modern OS with a supported desktop environment. If not, all manner of exceptions may be thrown.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The input event mask that corresponds to this platform's default modifier key(s) for command keyboard shortcuts.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Sound a beep, bell or other kind of audible alert, if supported by the desktop system.
    static void
    Copy a string of text to the default system clipboard.
    static File
    Get the default documents folder of the current user.
    static File
    Get the default images folder of the current user.
    static void
    main(String[] args)
     
    static boolean
    open(File file)
    Open a file in the associated application, or a directory in the default file manager.
    static boolean
    open(URL url)
    Open a URL in the default browser.
    static void
    setProgress(Window window, int percentage)
    Indicates the progress of an operation in the form of a progress bar on the task bar for supported systems; does nothing on unsupported systems.
    static void
    Indicates that progress should no longer be displayed on the task bar for supported systems; does nothing on unsupported systems.
    static void
    Indicates that an operation for which progress was being displayed on the task bar for supported systems has failed, for example by turning the progress bar red; does nothing on unsupported systems.

    Methods inherited from class java.lang.Object

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

    • PLATFORM_COMMAND_MASK

      public static final int PLATFORM_COMMAND_MASK
      The input event mask that corresponds to this platform's default modifier key(s) for command keyboard shortcuts.
  • Method Details

    • open

      public static boolean open(File file)
      Open a file in the associated application, or a directory in the default file manager.
      Parameters:
      file - The file or directory to open.
      Returns:
      true if the file or directory was successfully opened.
    • getDocumentsFolder

      public static File getDocumentsFolder()
      Get the default documents folder of the current user.
      Returns:
      The default documents folder of the current user, or the user's home directory if a documents folder could not be determined.
    • getPicturesFolder

      public static File getPicturesFolder()
      Get the default images folder of the current user.
      Returns:
      The default images folder of the current user, or the user's documents folder if an images folder could not be determined.
    • open

      public static boolean open(URL url)
      Open a URL in the default browser.
      Parameters:
      url - The URL to open.
      Returns:
      true if the URL was successfully opened.
    • copyToClipboard

      public static void copyToClipboard(String text)
      Copy a string of text to the default system clipboard.
      Parameters:
      text - The text to copy to the clipboard.
    • setProgress

      public static void setProgress(Window window, int percentage)
      Indicates the progress of an operation in the form of a progress bar on the task bar for supported systems; does nothing on unsupported systems.

      Once the operation has finished setProgressDone(Window) must always be invoked to clear the progress display from the task bar.

      Parameters:
      window - The window of which to use the task bar icon to display the progress.
      percentage - The progress to display out of 100.
    • setProgressDone

      public static void setProgressDone(Window window)
      Indicates that progress should no longer be displayed on the task bar for supported systems; does nothing on unsupported systems.
      Parameters:
      window - The window of which the task bar icon was being used to display progress.
    • setProgressError

      public static void setProgressError(Window window)
      Indicates that an operation for which progress was being displayed on the task bar for supported systems has failed, for example by turning the progress bar red; does nothing on unsupported systems.

      Once the operation has finished setProgressDone(Window) must always be invoked to clear the progress error state from the task bar.

      Parameters:
      window - The window of which the task bar icon was being used to display progress.
    • beep

      public static void beep()
      Sound a beep, bell or other kind of audible alert, if supported by the desktop system.
    • main

      public static void main(String[] args) throws MalformedURLException
      Throws:
      MalformedURLException