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