Package limn.backend

Class Launcher

java.lang.Object
limn.backend.Launcher

public final class Launcher extends Object
Hands an address or a file to the system the window is on: a web page to the browser, a mailto: to the mail program, a file to the program registered for its type, or a file to the file manager, shown selected in its folder. Reached from a window, NativeWindow.launcher(), because the system is told which window asked and brings what it opens in front of it.

 window.launcher().openAddress(URI.create("https://example.org/docs"));
 window.launcher().openFile(report);
 window.launcher().showInFolder(report);
 

Each call returns at once and its stage completes on the UI thread. true means the system took what it was handed, which is all a system tells a caller: not that a program opened, nor that the user saw it. false means it was not handed over (an address this class refuses, a file that is not there, no program registered, a window with no desktop under it), and the reason is logged as a warning. UI thread only.

Which addresses. An address often comes from data, and handed to a system as it is, text can start a program. So openAddress(java.net.URI) takes an absolute address whose scheme is http, https or mailto, and refuses the rest until the application says, once and for the process, that its addresses may be of another kind: allowScheme(java.lang.String). A file: address is never taken: a file is opened by openFile(java.nio.file.Path), whose argument is a path the application built.

  • Field Details

    • NONE

      public static final Launcher NONE
      The launcher of a window with no desktop under it (headless, embedded): always false.
  • Constructor Details

    • Launcher

      public Launcher(LauncherPeer peer)
      For a backend: the launcher of one of its windows.
      Parameters:
      peer - what hands things to the system
  • Method Details

    • allowScheme

      public static void allowScheme(String scheme)
      Lets openAddress(java.net.URI) take addresses of one more scheme, for the whole process: a tel: number, the application's own protocol. Said once where the application starts, since it is a fact about the application and not about one call. Any thread.
      Parameters:
      scheme - the scheme, without its colon; case does not matter
      Throws:
      IllegalArgumentException - for file, which openFile(java.nio.file.Path) opens, and for a text that is not a scheme
    • isAllowed

      public static boolean isAllowed(URI address)
      Whether openAddress(java.net.URI) would hand this address to the system: it is absolute, its scheme is allowed, and a web address names a host. Says nothing of whether a program is registered for it. Any thread.
      Parameters:
      address - the address
      Returns:
      whether it is one this class takes
    • openAddress

      public CompletionStage<Boolean> openAddress(URI address)
      Opens an address in the program the system has for it.
      Parameters:
      address - an absolute address of an allowed scheme
      Returns:
      whether the system took it; false at once for an address this class refuses
    • openFile

      public CompletionStage<Boolean> openFile(Path file)
      Opens a file in the program registered for its type, as a double click in the file manager does. For a program file that means running it.
      Parameters:
      file - the file, or a folder, which opens in the file manager
      Returns:
      whether the system took it; false at once for a path that does not exist
    • showInFolder

      public CompletionStage<Boolean> showInFolder(Path file)
      Shows a file in the file manager, selected in the folder it is in. Where the system can open the folder but not select in it, the folder opens and the answer is still true.
      Parameters:
      file - the file or folder to show
      Returns:
      whether the file manager was asked; false at once for a path that does not exist