001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.tools;
003
004import java.io.File;
005import java.io.IOException;
006import java.security.KeyStore;
007import java.security.KeyStoreException;
008import java.security.NoSuchAlgorithmException;
009import java.security.cert.CertificateException;
010
011/**
012 * This interface allows platform (operating system) dependent code
013 * to be bundled into self-contained classes.
014 * @since 1023
015 */
016public interface PlatformHook {
017
018    /**
019      * The preStartupHook will be called extremly early. It is
020      * guaranteed to be called before the GUI setup has started.
021      *
022      * Reason: On OSX we need to inform the Swing libraries
023      * that we want to be integrated with the OS before we setup our GUI.
024      */
025    public void preStartupHook();
026
027    /**
028      * The startupHook will be called early, but after the GUI
029      * setup has started.
030      *
031      * Reason: On OSX we need to register some callbacks with the
032      * OS, so we'll receive events from the system menu.
033      */
034    public void startupHook();
035
036    /**
037      * The openURL hook will be used to open an URL in the
038      * default web browser.
039     * @param url The URL to open
040     * @throws IOException if any I/O error occurs
041      */
042    public void openUrl(String url) throws IOException;
043
044    /**
045      * The initSystemShortcuts hook will be called by the
046      * Shortcut class after the modifier groups have been read
047      * from the config, but before any shortcuts are read from
048      * it or registered from within the application.
049      *
050      * Plese note that you are not allowed to register any
051      * shortuts from this hook, but only "systemCuts"!
052      *
053      * BTW: SystemCuts should be named "system:<whatever>",
054      * and it'd be best if sou'd recycle the names already used
055      * by the Windows and OSX hooks. Especially the later has
056      * really many of them.
057      *
058      * You should also register any and all shortcuts that the
059      * operation system handles itself to block JOSM from trying
060      * to use them---as that would just not work. Call setAutomatic
061      * on them to prevent the keyboard preferences from allowing the
062      * user to change them.
063      */
064    public void initSystemShortcuts();
065
066    /**
067      * The makeTooltip hook will be called whenever a tooltip for
068      * a menu or button is created.
069      *
070      * Tooltips are usually not system dependent, unless the
071      * JVM is too dumb to provide correct names for all the keys.
072      *
073      * Another reason not to use the implementation in the *nix
074      * hook are LAFs that don't understand HTML, such as the OSX LAFs.
075      *
076     * @param name Tooltip text to display
077     * @param sc Shortcut associated (to display accelerator between parenthesis)
078     * @return Full tooltip text (name + accelerator)
079      */
080    public String makeTooltip(String name, Shortcut sc);
081
082    /**
083     * Returns the default LAF to be used on this platform to look almost as a native application.
084     * @return The default native LAF for this platform
085     */
086    public String getDefaultStyle();
087
088    /**
089     * Determines if the platform allows full-screen.
090     * @return {@code true} if full screen is allowed, {@code false} otherwise
091     */
092    public boolean canFullscreen();
093
094    /**
095     * Renames a file.
096     * @param from Source file
097     * @param to Target file
098     * @return {@code true} if the file has been renamed, {@code false} otherwise
099     */
100    public boolean rename(File from, File to);
101
102    /**
103     * Returns a detailed OS description (at least family + version).
104     * @return A detailed OS description.
105     * @since 5850
106     */
107    public String getOSDescription();
108
109    /**
110     * Setup system keystore to add JOSM HTTPS certificate (for remote control).
111     * @param entryAlias The entry alias to use
112     * @param trustedCert the JOSM certificate for localhost
113     * @return {@code true} if something has changed as a result of the call (certificate installation, etc.)
114     * @throws KeyStoreException in case of error
115     * @throws IOException in case of error
116     * @throws CertificateException in case of error
117     * @throws NoSuchAlgorithmException in case of error
118     * @since 7343
119     */
120    public boolean setupHttpsCertificate(String entryAlias, KeyStore.TrustedCertificateEntry trustedCert)
121            throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException;
122}