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

Last change on this file since 11243 was 11156, checked in by bastiK, 7 years ago

rework/simplify inheritance structure of PlatformHook

PlatformHookUnixoid is no longer base class of PlatformHookWindows
and PlatformHookOsx; move common methods to PlatformHook

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