1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm;
|
---|
3 |
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.net.URL;
|
---|
6 | import java.util.Map;
|
---|
7 | import java.util.Set;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.Preferences;
|
---|
10 | import org.openstreetmap.josm.data.UndoRedoHandler;
|
---|
11 | import org.openstreetmap.josm.data.osm.IOsmDataManager;
|
---|
12 | import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
|
---|
13 | import org.openstreetmap.josm.data.projection.Projection;
|
---|
14 | import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
|
---|
15 | import org.openstreetmap.josm.data.projection.ProjectionRegistry;
|
---|
16 | import org.openstreetmap.josm.io.FileWatcher;
|
---|
17 | import org.openstreetmap.josm.io.NetworkManager;
|
---|
18 | import org.openstreetmap.josm.io.OnlineResource;
|
---|
19 | import org.openstreetmap.josm.spi.lifecycle.Lifecycle;
|
---|
20 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
21 | import org.openstreetmap.josm.spi.preferences.IUrls;
|
---|
22 | import org.openstreetmap.josm.tools.PlatformHook;
|
---|
23 | import org.openstreetmap.josm.tools.PlatformManager;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Abstract class holding various static global variables and methods used in large parts of JOSM application.
|
---|
27 | * @since 98
|
---|
28 | */
|
---|
29 | public abstract class Main implements IOsmDataManager {
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Global parent component for all dialogs and message boxes
|
---|
33 | */
|
---|
34 | public static Component parent;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Global application.
|
---|
38 | * @deprecated Not needed anymore
|
---|
39 | */
|
---|
40 | @Deprecated
|
---|
41 | public static volatile Main main;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Global application preferences
|
---|
45 | */
|
---|
46 | public static final Preferences pref = new Preferences(JosmBaseDirectories.getInstance());
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * The commands undo/redo handler.
|
---|
50 | * @deprecated Use {@link UndoRedoHandler#getInstance}
|
---|
51 | */
|
---|
52 | @Deprecated
|
---|
53 | public final UndoRedoHandler undoRedo = UndoRedoHandler.getInstance();
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * The file watcher service.
|
---|
57 | * @deprecated Use {@link FileWatcher#getDefaultInstance}
|
---|
58 | */
|
---|
59 | @Deprecated
|
---|
60 | public static final FileWatcher fileWatcher = FileWatcher.getDefaultInstance();
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Platform specific code goes in here.
|
---|
64 | * Plugins may replace it, however, some hooks will be called before any plugins have been loaded.
|
---|
65 | * So if you need to hook into those early ones, split your class and send the one with the early hooks
|
---|
66 | * to the JOSM team for inclusion.
|
---|
67 | * @deprecated Use {@link PlatformManager#getPlatform}
|
---|
68 | */
|
---|
69 | @Deprecated
|
---|
70 | public static final PlatformHook platform = PlatformManager.getPlatform();
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Constructs new {@code Main} object.
|
---|
74 | */
|
---|
75 | protected Main() {
|
---|
76 | setInstance(this);
|
---|
77 | }
|
---|
78 |
|
---|
79 | private static void setInstance(Main instance) {
|
---|
80 | main = instance;
|
---|
81 | }
|
---|
82 |
|
---|
83 | ///////////////////////////////////////////////////////////////////////////
|
---|
84 | // Implementation part
|
---|
85 | ///////////////////////////////////////////////////////////////////////////
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Closes JOSM and optionally terminates the Java Virtual Machine (JVM).
|
---|
89 | * @param exit If {@code true}, the JVM is terminated by running {@link System#exit} with a given return code.
|
---|
90 | * @param exitCode The return code
|
---|
91 | * @return {@code true}
|
---|
92 | * @since 12636
|
---|
93 | * @deprecated Use {@link Lifecycle#exitJosm}
|
---|
94 | */
|
---|
95 | @Deprecated
|
---|
96 | public static boolean exitJosm(boolean exit, int exitCode) {
|
---|
97 | return Lifecycle.exitJosm(exit, exitCode);
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Identifies the current operating system family and initializes the platform hook accordingly.
|
---|
102 | * @since 1849
|
---|
103 | * @deprecated Not needed anymore
|
---|
104 | */
|
---|
105 | @Deprecated
|
---|
106 | public static void determinePlatformHook() {
|
---|
107 | // Do nothing
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Replies the current projection.
|
---|
112 | *
|
---|
113 | * @return the currently active projection
|
---|
114 | * @deprecated Use {@link ProjectionRegistry#getProjection}
|
---|
115 | */
|
---|
116 | @Deprecated
|
---|
117 | public static Projection getProjection() {
|
---|
118 | return ProjectionRegistry.getProjection();
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Sets the current projection
|
---|
123 | *
|
---|
124 | * @param p the projection
|
---|
125 | * @deprecated Use {@link ProjectionRegistry#setProjection}
|
---|
126 | */
|
---|
127 | @Deprecated
|
---|
128 | public static void setProjection(Projection p) {
|
---|
129 | ProjectionRegistry.setProjection(p);
|
---|
130 | }
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Register a projection change listener.
|
---|
134 | * The listener is registered to be weak, so keep a reference of it if you want it to be preserved.
|
---|
135 | *
|
---|
136 | * @param listener the listener. Ignored if <code>null</code>.
|
---|
137 | * @deprecated Use {@link ProjectionRegistry#addProjectionChangeListener}
|
---|
138 | */
|
---|
139 | @Deprecated
|
---|
140 | public static void addProjectionChangeListener(ProjectionChangeListener listener) {
|
---|
141 | ProjectionRegistry.addProjectionChangeListener(listener);
|
---|
142 | }
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Removes a projection change listener.
|
---|
146 | *
|
---|
147 | * @param listener the listener. Ignored if <code>null</code>.
|
---|
148 | * @deprecated Use {@link ProjectionRegistry#removeProjectionChangeListener}
|
---|
149 | */
|
---|
150 | @Deprecated
|
---|
151 | public static void removeProjectionChangeListener(ProjectionChangeListener listener) {
|
---|
152 | ProjectionRegistry.removeProjectionChangeListener(listener);
|
---|
153 | }
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Remove all projection change listeners. For testing purposes only.
|
---|
157 | * @since 13322
|
---|
158 | * @deprecated Use {@link ProjectionRegistry#clearProjectionChangeListeners}
|
---|
159 | */
|
---|
160 | @Deprecated
|
---|
161 | public static void clearProjectionChangeListeners() {
|
---|
162 | ProjectionRegistry.clearProjectionChangeListeners();
|
---|
163 | }
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Adds a new network error that occur to give a hint about broken Internet connection.
|
---|
167 | * Do not use this method for errors known for sure thrown because of a bad proxy configuration.
|
---|
168 | *
|
---|
169 | * @param url The accessed URL that caused the error
|
---|
170 | * @param t The network error
|
---|
171 | * @return The previous error associated to the given resource, if any. Can be {@code null}
|
---|
172 | * @deprecated Use {@link NetworkManager#addNetworkError(URL, Throwable)}
|
---|
173 | * @since 6642
|
---|
174 | */
|
---|
175 | @Deprecated
|
---|
176 | public static Throwable addNetworkError(URL url, Throwable t) {
|
---|
177 | return NetworkManager.addNetworkError(url, t);
|
---|
178 | }
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Adds a new network error that occur to give a hint about broken Internet connection.
|
---|
182 | * Do not use this method for errors known for sure thrown because of a bad proxy configuration.
|
---|
183 | *
|
---|
184 | * @param url The accessed URL that caused the error
|
---|
185 | * @param t The network error
|
---|
186 | * @return The previous error associated to the given resource, if any. Can be {@code null}
|
---|
187 | * @deprecated Use {@link NetworkManager#addNetworkError(String, Throwable)}
|
---|
188 | * @since 6642
|
---|
189 | */
|
---|
190 | @Deprecated
|
---|
191 | public static Throwable addNetworkError(String url, Throwable t) {
|
---|
192 | return NetworkManager.addNetworkError(url, t);
|
---|
193 | }
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Returns the network errors that occured until now.
|
---|
197 | * @return the network errors that occured until now, indexed by URL
|
---|
198 | * @deprecated Use {@link NetworkManager#getNetworkErrors}
|
---|
199 | * @since 6639
|
---|
200 | */
|
---|
201 | @Deprecated
|
---|
202 | public static Map<String, Throwable> getNetworkErrors() {
|
---|
203 | return NetworkManager.getNetworkErrors();
|
---|
204 | }
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Clears the network errors cache.
|
---|
208 | * @deprecated Use {@link NetworkManager#clearNetworkErrors}
|
---|
209 | * @since 12011
|
---|
210 | */
|
---|
211 | @Deprecated
|
---|
212 | public static void clearNetworkErrors() {
|
---|
213 | NetworkManager.clearNetworkErrors();
|
---|
214 | }
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Returns the JOSM website URL.
|
---|
218 | * @return the josm website URL
|
---|
219 | * @deprecated Use {@link IUrls#getJOSMWebsite}
|
---|
220 | * @since 6897
|
---|
221 | */
|
---|
222 | @Deprecated
|
---|
223 | public static String getJOSMWebsite() {
|
---|
224 | return Config.getUrls().getJOSMWebsite();
|
---|
225 | }
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Returns the JOSM XML URL.
|
---|
229 | * @return the josm XML URL
|
---|
230 | * @deprecated Use {@link IUrls#getXMLBase}
|
---|
231 | * @since 6897
|
---|
232 | */
|
---|
233 | @Deprecated
|
---|
234 | public static String getXMLBase() {
|
---|
235 | return Config.getUrls().getXMLBase();
|
---|
236 | }
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * Returns the OSM website URL.
|
---|
240 | * @return the OSM website URL
|
---|
241 | * @deprecated Use {@link IUrls#getOSMWebsite}
|
---|
242 | * @since 6897
|
---|
243 | */
|
---|
244 | @Deprecated
|
---|
245 | public static String getOSMWebsite() {
|
---|
246 | return Config.getUrls().getOSMWebsite();
|
---|
247 | }
|
---|
248 |
|
---|
249 | /**
|
---|
250 | * Replies the base URL for browsing information about a primitive.
|
---|
251 | * @return the base URL, i.e. https://www.openstreetmap.org
|
---|
252 | * @deprecated Use {@link IUrls#getBaseBrowseUrl}
|
---|
253 | * @since 7678
|
---|
254 | */
|
---|
255 | @Deprecated
|
---|
256 | public static String getBaseBrowseUrl() {
|
---|
257 | return Config.getUrls().getBaseBrowseUrl();
|
---|
258 | }
|
---|
259 |
|
---|
260 | /**
|
---|
261 | * Replies the base URL for browsing information about a user.
|
---|
262 | * @return the base URL, i.e. https://www.openstreetmap.org/user
|
---|
263 | * @deprecated Use {@link IUrls#getBaseUserUrl}
|
---|
264 | * @since 7678
|
---|
265 | */
|
---|
266 | @Deprecated
|
---|
267 | public static String getBaseUserUrl() {
|
---|
268 | return Config.getUrls().getBaseUserUrl();
|
---|
269 | }
|
---|
270 |
|
---|
271 | /**
|
---|
272 | * Determines if we are currently running on OSX.
|
---|
273 | * @return {@code true} if we are currently running on OSX
|
---|
274 | * @since 6957
|
---|
275 | * @deprecated Use {@link PlatformManager#isPlatformOsx}
|
---|
276 | */
|
---|
277 | @Deprecated
|
---|
278 | public static boolean isPlatformOsx() {
|
---|
279 | return PlatformManager.isPlatformOsx();
|
---|
280 | }
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * Determines if we are currently running on Windows.
|
---|
284 | * @return {@code true} if we are currently running on Windows
|
---|
285 | * @since 7335
|
---|
286 | * @deprecated Use {@link PlatformManager#isPlatformWindows}
|
---|
287 | */
|
---|
288 | @Deprecated
|
---|
289 | public static boolean isPlatformWindows() {
|
---|
290 | return PlatformManager.isPlatformWindows();
|
---|
291 | }
|
---|
292 |
|
---|
293 | /**
|
---|
294 | * Determines if the given online resource is currently offline.
|
---|
295 | * @param r the online resource
|
---|
296 | * @return {@code true} if {@code r} is offline and should not be accessed
|
---|
297 | * @deprecated Use {@link NetworkManager#isOffline}
|
---|
298 | * @since 7434
|
---|
299 | */
|
---|
300 | @Deprecated
|
---|
301 | public static boolean isOffline(OnlineResource r) {
|
---|
302 | return NetworkManager.isOffline(r);
|
---|
303 | }
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Sets the given online resource to offline state.
|
---|
307 | * @param r the online resource
|
---|
308 | * @return {@code true} if {@code r} was not already offline
|
---|
309 | * @deprecated Use {@link NetworkManager#setOffline}
|
---|
310 | * @since 7434
|
---|
311 | */
|
---|
312 | @Deprecated
|
---|
313 | public static boolean setOffline(OnlineResource r) {
|
---|
314 | return NetworkManager.setOffline(r);
|
---|
315 | }
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Sets the given online resource to online state.
|
---|
319 | * @param r the online resource
|
---|
320 | * @return {@code true} if {@code r} was offline
|
---|
321 | * @deprecated Use {@link NetworkManager#setOnline}
|
---|
322 | * @since 8506
|
---|
323 | */
|
---|
324 | @Deprecated
|
---|
325 | public static boolean setOnline(OnlineResource r) {
|
---|
326 | return NetworkManager.setOnline(r);
|
---|
327 | }
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * Replies the set of online resources currently offline.
|
---|
331 | * @return the set of online resources currently offline
|
---|
332 | * @deprecated Use {@link NetworkManager#getOfflineResources}
|
---|
333 | * @since 7434
|
---|
334 | */
|
---|
335 | @Deprecated
|
---|
336 | public static Set<OnlineResource> getOfflineResources() {
|
---|
337 | return NetworkManager.getOfflineResources();
|
---|
338 | }
|
---|
339 | }
|
---|