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