Package org.openstreetmap.josm.tools
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.WebStartMigrationCallback
Called when Oracle Java WebStart is detected at startup.
-
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 void
checkWebStartMigration(PlatformHook.WebStartMigrationCallback callback)
Checks if we run Oracle Web Start, proposes to user to migrate to OpenWebStart.default String
exec(String... command)
Executes a native command and returns the first line of standard output.File
getDefaultCacheDirectory()
Returns the platform-dependent default cache directory.File
getDefaultPrefDirectory()
Returns the platform-dependent default preferences directory.default List<File>
getDefaultProj4NadshiftDirectories()
Returns the list of platform-dependent default datum shifting directories for the PROJ.4 library.String
getDefaultStyle()
Returns the default LAF to be used on this platform to look almost as a native application.File
getDefaultUserDataDirectory()
Returns the platform-dependent default user data directory.default int
getMenuShortcutKeyMaskEx()
Returns extended modifier key used as the appropriate accelerator key for menu shortcuts.default String
getOSBuildNumber()
Returns OS build number.String
getOSDescription()
Returns a detailed OS description (at least family + version).Platform
getPlatform()
Get the platform corresponding to this platform hook.default Collection<String>
getPossiblePreferenceDirs()
Returns a set of possible platform specific directories where resources could be stored.default 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(String url)
The openURL hook will be used to open an URL in the default web browser.default void
preStartupHook()
The preStartupHook will be called extremely early.default boolean
rename(File from, File to)
Renames a file.default File
resolveFileLink(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.WebStartMigrationCallback webStartCallback)
The startupHook will be called early, but after the GUI setup has started.
-
-
-
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.WebStartMigrationCallback webStartCallback)
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 feedbackwebStartCallback
- WebStart migration callback, providing GUI feedback- Since:
- 17679 (signature)
-
openUrl
void openUrl(String url) throws IOException
The openURL hook will be used to open an URL in the default web browser.- Parameters:
url
- The URL to open- Throws:
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 later has really many of them. You should also register any and all shortcuts that the operation 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
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(File from, File to)
Renames a file.- Parameters:
from
- Source fileto
- Target file- Returns:
true
if the file has been renamed,false
otherwise
-
getOSDescription
String getOSDescription()
Returns a detailed OS description (at least family + version).- Returns:
- A detailed OS description.
- Since:
- 5850
-
getOSBuildNumber
default String getOSBuildNumber()
Returns OS build number.- Returns:
- OS build number.
- Since:
- 12217
-
getX509Certificate
default X509Certificate getX509Certificate(CertificateAmendment.NativeCertAmend certAmend) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException
Returns theX509Certificate
matching the given certificate amendment information.- Parameters:
certAmend
- certificate amendment- Returns:
- the
X509Certificate
matching the given certificate amendment information, ornull
- Throws:
KeyStoreException
- in case of errorIOException
- in case of errorCertificateException
- in case of errorNoSuchAlgorithmException
- 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
File getDefaultCacheDirectory()
Returns the platform-dependent default cache directory.- Returns:
- the platform-dependent default cache directory
- Since:
- 7829
-
getDefaultPrefDirectory
File getDefaultPrefDirectory()
Returns the platform-dependent default preferences directory.- Returns:
- the platform-dependent default preferences directory
- Since:
- 7831
-
getDefaultUserDataDirectory
File getDefaultUserDataDirectory()
Returns the platform-dependent default user data directory.- Returns:
- the platform-dependent default user data directory
- Since:
- 7834
-
getDefaultProj4NadshiftDirectories
default List<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 is 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
-
checkWebStartMigration
default void checkWebStartMigration(PlatformHook.WebStartMigrationCallback callback)
Checks if we run Oracle Web Start, proposes to user to migrate to OpenWebStart.- Parameters:
callback
- WebStart migration callback- Since:
- 17679
-
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 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
default Collection<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
-
-