source: josm/trunk/src/org/openstreetmap/josm/tools/PlatformHook.java@ 11995

Last change on this file since 11995 was 11944, checked in by Don-vip, 7 years ago

see #14649 - fix @since

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