Interface PlatformHook

All Known Implementing Classes:
PlatformHookOsx, PlatformHookUnixoid, PlatformHookWindows

public interface PlatformHook
This interface allows platform (operating system) dependent code to be bundled into self-contained classes.
Since:
1023
  • Field Details

  • Method Details

    • getPlatform

      Get the platform corresponding to this platform hook.
      Returns:
      the platform corresponding to this platform hook
    • preStartupHook

      default void preStartupHook()
      The preStartupHook will be called extremely early. It is guaranteed to be called before the GUI setup has started.

      Reason: On OSX we need to inform the Swing libraries that we want to be integrated with the OS before we setup our GUI.

    • afterPrefStartupHook

      default void afterPrefStartupHook()
      The afterPrefStartupHook will be called early, but after the preferences have been loaded and basic processing of command line arguments is finished. It is guaranteed to be called before the GUI setup has started.
    • startupHook

      default void startupHook(PlatformHook.JavaExpirationCallback javaCallback, PlatformHook.SanityCheckCallback sanityCheckCallback)
      The startupHook will be called early, but after the GUI setup has started.

      Reason: On OSX we need to register some callbacks with the OS, so we'll receive events from the system menu.

      Parameters:
      javaCallback - Java expiration callback, providing GUI feedback
      sanityCheckCallback - Sanity check callback, providing GUI feedback
      Since:
      18985
    • openUrl

      void openUrl(String url) throws IOException
      The openURL hook will be used to open a URL in the default web browser.
      Parameters:
      url - The URL to open
      Throws:
      IOException - if any I/O error occurs
    • initSystemShortcuts

      The initSystemShortcuts hook will be called by the Shortcut class after the modifier groups have been read from the config, but before any shortcuts are read from it or registered from within the application.

      Please note that you are not allowed to register any shortcuts from this hook, but only "systemCuts"!

      BTW: SystemCuts should be named "system:<whatever>", and it'd be best if you'd recycle the names already used by the Windows and OSX hooks. Especially the latter has really many of them.

      You should also register any and all shortcuts that the operating system handles itself to block JOSM from trying to use them---as that would just not work. Call setAutomatic on them to prevent the keyboard preferences from allowing the user to change them.

    • getDefaultStyle

      Returns the default LAF to be used on this platform to look almost as a native application.
      Returns:
      The default native LAF for this platform
    • canFullscreen

      default boolean canFullscreen()
      Determines if the platform allows full-screen.
      Returns:
      true if full screen is allowed, false otherwise
    • rename

      default boolean rename(File from, File to)
      Renames a file.
      Parameters:
      from - Source file
      to - Target file
      Returns:
      true if the file has been renamed, false otherwise
    • getOSDescription

      Returns a detailed OS description (at least family + version).
      Returns:
      A detailed OS description.
      Since:
      5850
    • getOSBuildNumber

      Returns OS build number.
      Returns:
      OS build number.
      Since:
      12217
    • getX509Certificate

      Returns the X509Certificate matching the given certificate amendment information.
      Parameters:
      certAmend - certificate amendment
      Returns:
      the X509Certificate matching the given certificate amendment information, or null
      Throws:
      KeyStoreException - in case of error
      IOException - in case of error
      CertificateException - in case of error
      NoSuchAlgorithmException - in case of error
      Since:
      13450
    • exec

      default String exec(String... command) throws IOException
      Executes a native command and returns the first line of standard output.
      Parameters:
      command - array containing the command to call and its arguments.
      Returns:
      first stripped line of standard output
      Throws:
      IOException - if an I/O error occurs
      Since:
      12217
    • getDefaultCacheDirectory

      Returns the platform-dependent default cache directory.
      Returns:
      the platform-dependent default cache directory
      Since:
      7829
    • getDefaultPrefDirectory

      Returns the platform-dependent default preferences directory.
      Returns:
      the platform-dependent default preferences directory
      Since:
      7831
    • getDefaultUserDataDirectory

      Returns the platform-dependent default user data directory.
      Returns:
      the platform-dependent default user data directory
      Since:
      7834
    • getDefaultProj4NadshiftDirectories

      Returns the list of platform-dependent default datum shifting directories for the PROJ.4 library.
      Returns:
      the list of platform-dependent default datum shifting directories for the PROJ.4 library
      Since:
      11642
    • isOpenJDK

      default boolean isOpenJDK()
      Determines if the JVM is OpenJDK-based.
      Returns:
      true if java.home contains "openjdk", false otherwise
      Since:
      12219
    • isHtmlSupportedInMenuTooltips

      default boolean isHtmlSupportedInMenuTooltips()
      Determines if HTML rendering is supported in menu tooltips.
      Returns:
      true if HTML rendering is supported in menu tooltips
      Since:
      18116
    • getMenuShortcutKeyMaskEx

      default int getMenuShortcutKeyMaskEx()
      Returns extended modifier key used as the appropriate accelerator key for menu shortcuts. It was advised everywhere to use Toolkit.getMenuShortcutKeyMask() to get the cross-platform modifier, but:
      • it returns KeyEvent.CTRL_MASK instead of KeyEvent.CTRL_DOWN_MASK. We used the extended modifier for years, and Oracle recommends to use it instead, so it's best to keep it
      • the method throws a HeadlessException ! So we would need to handle it for unit tests anyway
      Returns:
      extended modifier key used as the appropriate accelerator key for menu shortcuts
      Since:
      12748 (as a replacement to GuiHelper.getMenuShortcutKeyMaskEx())
    • warnSoonToBeUnsupportedJava

      Checks if we will soon not be supporting the running version of Java
      Parameters:
      callback - Java expiration callback
      Since:
      18580
    • getJavaUrl

      default String getJavaUrl()
      Get the Java download URL (really shouldn't be used outside of JOSM startup checks)
      Returns:
      The download URL to use.
      Since:
      18580
    • startupSanityChecks

      default void startupSanityChecks(PlatformHook.SanityCheckCallback sanityCheckCallback)
      Check startup preconditions
      Parameters:
      sanityCheckCallback - The callback to inform the user about failed checks
    • setNativeOsCallback

      Registers the native OS callback. Currently only needed for macOS.
      Parameters:
      callback - the native OS callback
      Since:
      12695
    • resolveFileLink

      default File resolveFileLink(File file)
      Resolves a file link to its destination file.
      Parameters:
      file - file (link or regular file)
      Returns:
      destination file in case of a file link, file if regular
      Since:
      13691
    • getPossiblePreferenceDirs

      Returns a set of possible platform specific directories where resources could be stored.
      Returns:
      A set of possible platform specific directories where resources could be stored.
      Since:
      14144