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
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
PlatformHook.JavaExpirationCallback
Called when an outdated version of Java is detected at startup.static interface
PlatformHook.NativeOsCallback
Called when interfacing with native OS functions.static interface
PlatformHook.SanityCheckCallback
Inform the user that a sanity check or checks failed
-
Field Summary
Fields Modifier and Type Field Description static PlatformVisitor<PlatformHook>
CONSTRUCT_FROM_PLATFORM
Visitor to construct a PlatformHook from a givenPlatform
object.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description 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.default boolean
canFullscreen()
Determines if the platform allows full-screen.default void
checkExpiredJava(PlatformHook.JavaExpirationCallback callback)
Checks if the running version of Java has expired, proposes to user to update it if needed.default java.lang.String
exec(java.lang.String... command)
Executes a native command and returns the first line of standard output.java.io.File
getDefaultCacheDirectory()
Returns the platform-dependent default cache directory.java.io.File
getDefaultPrefDirectory()
Returns the platform-dependent default preferences directory.default java.util.List<java.io.File>
getDefaultProj4NadshiftDirectories()
Returns the list of platform-dependent default datum shifting directories for the PROJ.4 library.java.lang.String
getDefaultStyle()
Returns the default LAF to be used on this platform to look almost as a native application.java.io.File
getDefaultUserDataDirectory()
Returns the platform-dependent default user data directory.default java.lang.String
getJavaUrl()
Get the Java download URL (really shouldn't be used outside of JOSM startup checks)default int
getMenuShortcutKeyMaskEx()
Returns extended modifier key used as the appropriate accelerator key for menu shortcuts.default java.lang.String
getOSBuildNumber()
Returns OS build number.java.lang.String
getOSDescription()
Returns a detailed OS description (at least family + version).Platform
getPlatform()
Get the platform corresponding to this platform hook.default java.util.Collection<java.lang.String>
getPossiblePreferenceDirs()
Returns a set of possible platform specific directories where resources could be stored.default java.security.cert.X509Certificate
getX509Certificate(CertificateAmendment.NativeCertAmend certAmend)
Returns theX509Certificate
matching the given certificate amendment information.void
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.default boolean
isHtmlSupportedInMenuTooltips()
Determines if HTML rendering is supported in menu tooltips.default boolean
isOpenJDK()
Determines if the JVM is OpenJDK-based.void
openUrl(java.lang.String url)
The openURL hook will be used to open a URL in the default web browser.default void
preStartupHook()
The preStartupHook will be called extremely early.default boolean
rename(java.io.File from, java.io.File to)
Renames a file.default java.io.File
resolveFileLink(java.io.File file)
Resolves a file link to its destination file.default void
setNativeOsCallback(PlatformHook.NativeOsCallback callback)
Registers the native OS callback.default void
startupHook(PlatformHook.JavaExpirationCallback javaCallback, PlatformHook.SanityCheckCallback sanityCheckCallback)
The startupHook will be called early, but after the GUI setup has started.default void
startupSanityChecks(PlatformHook.SanityCheckCallback sanityCheckCallback)
Check startup preconditionsdefault void
warnSoonToBeUnsupportedJava(PlatformHook.JavaExpirationCallback callback)
Checks if we will soon not be supporting the running version of Java
-
-
-
Field Detail
-
CONSTRUCT_FROM_PLATFORM
static final PlatformVisitor<PlatformHook> CONSTRUCT_FROM_PLATFORM
Visitor to construct a PlatformHook from a givenPlatform
object.
-
-
Method Detail
-
getPlatform
Platform 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 feedbacksanityCheckCallback
- Sanity check callback, providing GUI feedback- Since:
- 18985
-
openUrl
void openUrl(java.lang.String url) throws java.io.IOException
The openURL hook will be used to open a URL in the default web browser.- Parameters:
url
- The URL to open- Throws:
java.io.IOException
- if any I/O error occurs
-
initSystemShortcuts
void 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
java.lang.String 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(java.io.File from, java.io.File to)
Renames a file.- Parameters:
from
- Source fileto
- Target file- Returns:
true
if the file has been renamed,false
otherwise
-
getOSDescription
java.lang.String getOSDescription()
Returns a detailed OS description (at least family + version).- Returns:
- A detailed OS description.
- Since:
- 5850
-
getOSBuildNumber
default java.lang.String getOSBuildNumber()
Returns OS build number.- Returns:
- OS build number.
- Since:
- 12217
-
getX509Certificate
default java.security.cert.X509Certificate getX509Certificate(CertificateAmendment.NativeCertAmend certAmend) throws java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.io.IOException
Returns theX509Certificate
matching the given certificate amendment information.- Parameters:
certAmend
- certificate amendment- Returns:
- the
X509Certificate
matching the given certificate amendment information, ornull
- Throws:
java.security.KeyStoreException
- in case of errorjava.io.IOException
- in case of errorjava.security.cert.CertificateException
- in case of errorjava.security.NoSuchAlgorithmException
- in case of error- Since:
- 13450
-
exec
default java.lang.String exec(java.lang.String... command) throws java.io.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:
java.io.IOException
- if an I/O error occurs- Since:
- 12217
-
getDefaultCacheDirectory
java.io.File getDefaultCacheDirectory()
Returns the platform-dependent default cache directory.- Returns:
- the platform-dependent default cache directory
- Since:
- 7829
-
getDefaultPrefDirectory
java.io.File getDefaultPrefDirectory()
Returns the platform-dependent default preferences directory.- Returns:
- the platform-dependent default preferences directory
- Since:
- 7831
-
getDefaultUserDataDirectory
java.io.File getDefaultUserDataDirectory()
Returns the platform-dependent default user data directory.- Returns:
- the platform-dependent default user data directory
- Since:
- 7834
-
getDefaultProj4NadshiftDirectories
default java.util.List<java.io.File> 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
ifjava.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 useToolkit.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()
)
-
checkExpiredJava
default void checkExpiredJava(PlatformHook.JavaExpirationCallback callback)
Checks if the running version of Java has expired, proposes to user to update it if needed.- Parameters:
callback
- Java expiration callback- Since:
- 12270 (signature), 12219
-
warnSoonToBeUnsupportedJava
default void warnSoonToBeUnsupportedJava(PlatformHook.JavaExpirationCallback callback)
Checks if we will soon not be supporting the running version of Java- Parameters:
callback
- Java expiration callback- Since:
- 18580
-
getJavaUrl
default java.lang.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
default void setNativeOsCallback(PlatformHook.NativeOsCallback callback)
Registers the native OS callback. Currently only needed for macOS.- Parameters:
callback
- the native OS callback- Since:
- 12695
-
resolveFileLink
default java.io.File resolveFileLink(java.io.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
default java.util.Collection<java.lang.String> 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
-
-