1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import java.awt.GraphicsEnvironment;
|
---|
5 | import java.io.File;
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.security.KeyStore;
|
---|
8 | import java.security.KeyStoreException;
|
---|
9 | import java.security.NoSuchAlgorithmException;
|
---|
10 | import java.security.cert.CertificateException;
|
---|
11 | import java.util.List;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * This interface allows platform (operating system) dependent code
|
---|
15 | * to be bundled into self-contained classes.
|
---|
16 | * @since 1023
|
---|
17 | */
|
---|
18 | public interface PlatformHook {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * The preStartupHook will be called extremly early. It is
|
---|
22 | * guaranteed to be called before the GUI setup has started.
|
---|
23 | *
|
---|
24 | * Reason: On OSX we need to inform the Swing libraries
|
---|
25 | * that we want to be integrated with the OS before we setup our GUI.
|
---|
26 | */
|
---|
27 | default void preStartupHook() {
|
---|
28 | // Do nothing
|
---|
29 | }
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * The afterPrefStartupHook will be called early, but after
|
---|
33 | * the preferences have been loaded and basic processing of
|
---|
34 | * command line arguments is finished.
|
---|
35 | * It is guaranteed to be called before the GUI setup has started.
|
---|
36 | */
|
---|
37 | default void afterPrefStartupHook() {
|
---|
38 | // Do nothing
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * The startupHook will be called early, but after the GUI
|
---|
43 | * setup has started.
|
---|
44 | *
|
---|
45 | * Reason: On OSX we need to register some callbacks with the
|
---|
46 | * OS, so we'll receive events from the system menu.
|
---|
47 | */
|
---|
48 | default void startupHook() {
|
---|
49 | // Do nothing
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * The openURL hook will be used to open an URL in the
|
---|
54 | * default web browser.
|
---|
55 | * @param url The URL to open
|
---|
56 | * @throws IOException if any I/O error occurs
|
---|
57 | */
|
---|
58 | void openUrl(String url) throws IOException;
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * The initSystemShortcuts hook will be called by the
|
---|
62 | * Shortcut class after the modifier groups have been read
|
---|
63 | * from the config, but before any shortcuts are read from
|
---|
64 | * it or registered from within the application.
|
---|
65 | *
|
---|
66 | * Plese note that you are not allowed to register any
|
---|
67 | * shortuts from this hook, but only "systemCuts"!
|
---|
68 | *
|
---|
69 | * BTW: SystemCuts should be named "system:<whatever>",
|
---|
70 | * and it'd be best if sou'd recycle the names already used
|
---|
71 | * by the Windows and OSX hooks. Especially the later has
|
---|
72 | * really many of them.
|
---|
73 | *
|
---|
74 | * You should also register any and all shortcuts that the
|
---|
75 | * operation system handles itself to block JOSM from trying
|
---|
76 | * to use them---as that would just not work. Call setAutomatic
|
---|
77 | * on them to prevent the keyboard preferences from allowing the
|
---|
78 | * user to change them.
|
---|
79 | */
|
---|
80 | void initSystemShortcuts();
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * The makeTooltip hook will be called whenever a tooltip for
|
---|
84 | * a menu or button is created.
|
---|
85 | *
|
---|
86 | * Tooltips are usually not system dependent, unless the
|
---|
87 | * JVM is too dumb to provide correct names for all the keys.
|
---|
88 | *
|
---|
89 | * Some LAFs don't understand HTML, such as the OSX LAFs.
|
---|
90 | *
|
---|
91 | * @param name Tooltip text to display
|
---|
92 | * @param sc Shortcut associated (to display accelerator between parenthesis)
|
---|
93 | * @return Full tooltip text (name + accelerator)
|
---|
94 | */
|
---|
95 | default String makeTooltip(String name, Shortcut sc) {
|
---|
96 | StringBuilder result = new StringBuilder();
|
---|
97 | result.append("<html>").append(name);
|
---|
98 | if (sc != null && !sc.getKeyText().isEmpty()) {
|
---|
99 | result.append(" <font size='-2'>(")
|
---|
100 | .append(sc.getKeyText())
|
---|
101 | .append(")</font>");
|
---|
102 | }
|
---|
103 | return result.append(" </html>").toString();
|
---|
104 | }
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Returns the default LAF to be used on this platform to look almost as a native application.
|
---|
108 | * @return The default native LAF for this platform
|
---|
109 | */
|
---|
110 | String getDefaultStyle();
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Determines if the platform allows full-screen.
|
---|
114 | * @return {@code true} if full screen is allowed, {@code false} otherwise
|
---|
115 | */
|
---|
116 | default boolean canFullscreen() {
|
---|
117 | return !GraphicsEnvironment.isHeadless() &&
|
---|
118 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().isFullScreenSupported();
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Renames a file.
|
---|
123 | * @param from Source file
|
---|
124 | * @param to Target file
|
---|
125 | * @return {@code true} if the file has been renamed, {@code false} otherwise
|
---|
126 | */
|
---|
127 | default boolean rename(File from, File to) {
|
---|
128 | return from.renameTo(to);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Returns a detailed OS description (at least family + version).
|
---|
133 | * @return A detailed OS description.
|
---|
134 | * @since 5850
|
---|
135 | */
|
---|
136 | String getOSDescription();
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Setup system keystore to add JOSM HTTPS certificate (for remote control).
|
---|
140 | * @param entryAlias The entry alias to use
|
---|
141 | * @param trustedCert the JOSM certificate for localhost
|
---|
142 | * @return {@code true} if something has changed as a result of the call (certificate installation, etc.)
|
---|
143 | * @throws KeyStoreException in case of error
|
---|
144 | * @throws IOException in case of error
|
---|
145 | * @throws CertificateException in case of error
|
---|
146 | * @throws NoSuchAlgorithmException in case of error
|
---|
147 | * @since 7343
|
---|
148 | */
|
---|
149 | default boolean setupHttpsCertificate(String entryAlias, KeyStore.TrustedCertificateEntry trustedCert)
|
---|
150 | throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
|
---|
151 | // TODO setup HTTPS certificate on Unix and OS X systems
|
---|
152 | return false;
|
---|
153 | }
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Returns the platform-dependent default cache directory.
|
---|
157 | * @return the platform-dependent default cache directory
|
---|
158 | * @since 7829
|
---|
159 | */
|
---|
160 | File getDefaultCacheDirectory();
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Returns the platform-dependent default preferences directory.
|
---|
164 | * @return the platform-dependent default preferences directory
|
---|
165 | * @since 7831
|
---|
166 | */
|
---|
167 | File getDefaultPrefDirectory();
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Returns the platform-dependent default user data directory.
|
---|
171 | * @return the platform-dependent default user data directory
|
---|
172 | * @since 7834
|
---|
173 | */
|
---|
174 | File getDefaultUserDataDirectory();
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Returns the list of platform-dependent default datum shifting directories for the PROJ.4 library.
|
---|
178 | * @return the list of platform-dependent default datum shifting directories for the PROJ.4 library
|
---|
179 | * @since 11642
|
---|
180 | */
|
---|
181 | List<File> getDefaultProj4NadshiftDirectories();
|
---|
182 | }
|
---|