source: josm/trunk/src/org/openstreetmap/josm/Main.java@ 14152

Last change on this file since 14152 was 14150, checked in by Don-vip, 6 years ago

see #15229 - make sure Main.pref has the correct global value

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