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

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

see #15229 - deprecate Main.parent and Main itself

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