public abstract class Main extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
Main.DownloadParamType
The type of a command line parameter, to be used in switch statements.
|
private class |
Main.InitializationTask |
static interface |
Main.InitStatusListener |
protected static class |
Main.MasterWindowListener
WindowListener, that is registered on all Windows of the application.
|
private static class |
Main.WindowPositionSizeListener |
static interface |
Main.WindowSwitchListener
Listener for window switch events.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
commandLineArgs
Command-line arguments used to run the application.
|
protected static javax.swing.JPanel |
contentPanePrivate |
static PleaseWaitProgressMonitor |
currentProgressMonitor
The progress monitor being currently displayed.
|
private static java.util.List<java.lang.String> |
ERRORS_AND_WARNINGS |
static FileWatcher |
fileWatcher
The file watcher service.
|
protected static WindowGeometry |
geometry |
GettingStarted |
gettingStarted
The MOTD Layer.
|
private static Main.InitStatusListener |
initListener |
static boolean |
isOpenjdk
Whether or not the java vm is openjdk
We use this to work around openjdk bugs
|
private static java.lang.String |
JOSM_WEBSITE
The JOSM website URL.
|
private static java.util.List<java.lang.ref.WeakReference<ProjectionChangeListener>> |
listeners |
static int |
logLevel
Logging level (5 = trace, 4 = debug, 3 = info, 2 = warn, 1 = error, 0 = none).
|
static Main |
main
Global application.
|
static MapFrame |
map
The MapFrame.
|
private static java.util.Collection<MapFrameListener> |
mapFrameListeners |
MainMenu |
menu
The main menu bar at top of screen.
|
protected static java.util.Map<java.lang.String,java.lang.Throwable> |
NETWORK_ERRORS |
private static java.util.Set<OnlineResource> |
OFFLINE_RESOURCES |
private static java.lang.String |
OSM_WEBSITE
The OSM website URL.
|
static javax.swing.JPanel |
panel
Global panel.
|
static java.awt.Component |
parent
Global parent component for all dialogs and message boxes
|
static PrimitiveDeepCopy |
pasteBuffer
The global paste buffer.
|
static Layer |
pasteSource
The layer source from which
pasteBuffer data comes from. |
static PlatformHook |
platform
Platform specific code goes in here.
|
static Preferences |
pref
Global application preferences
|
private static Projection |
proj
The projection method used.
|
private OsmDataLayer.CommandQueueListener |
redoUndoListener |
static ToolbarPreferences |
toolbar
The toolbar preference control to register new actions.
|
UndoRedoHandler |
undoRedo
The commands undo/redo handler.
|
OsmValidator |
validator
The data validation handler.
|
protected static int |
windowState |
private static java.util.List<java.lang.ref.WeakReference<Main.WindowSwitchListener>> |
windowSwitchListeners |
static java.util.concurrent.ExecutorService |
worker
The worker thread slave.
|
Constructor and Description |
---|
Main()
Constructs new
Main object. |
Modifier and Type | Method and Description |
---|---|
void |
addLayer(Layer layer)
Add a new layer to the map.
|
void |
addLayer(Layer layer,
ProjectionBounds bounds)
Add a new layer to the map.
|
void |
addLayer(Layer layer,
ViewportData viewport)
Add a new layer to the map.
|
protected static void |
addListener() |
static boolean |
addMapFrameListener(MapFrameListener listener)
Registers a new
MapFrameListener that will be notified of MapFrame changes |
static boolean |
addMapFrameListener(MapFrameListener listener,
boolean fireWhenMapViewPresent)
Registers a new
MapFrameListener that will be notified of MapFrame changes |
static java.lang.Throwable |
addNetworkError(java.lang.String url,
java.lang.Throwable t)
Adds a new network error that occur to give a hint about broken Internet connection.
|
static java.lang.Throwable |
addNetworkError(java.net.URL url,
java.lang.Throwable t)
Adds a new network error that occur to give a hint about broken Internet connection.
|
static void |
addProjectionChangeListener(ProjectionChangeListener listener)
Register a projection change listener.
|
static void |
addWindowSwitchListener(Main.WindowSwitchListener listener)
Register a window switch listener.
|
static void |
checkJavaVersion()
Checks that JOSM is at least running with Java 7.
|
void |
createMapFrame(Layer firstLayer,
ViewportData viewportData) |
static void |
debug(java.lang.String msg)
Prints a debug message if logging is on.
|
static void |
debug(java.lang.String msg,
java.lang.Object... objects)
Prints a formatted debug message if logging is on.
|
static void |
determinePlatformHook()
Identifies the current operating system family and initializes the platform hook accordingly.
|
private static void |
downloadFromParamBounds(boolean rawGps,
Bounds b)
Download area specified as Bounds value.
|
private static void |
downloadFromParamBounds(boolean rawGps,
java.lang.String s)
Download area specified on the command line as bounds string.
|
private static void |
downloadFromParamHttp(boolean rawGps,
java.lang.String s)
Download area specified on the command line as OSM URL.
|
static void |
error(java.lang.String msg)
Prints an error message if logging is on.
|
static void |
error(java.lang.String msg,
java.lang.Object... objects)
Prints a formatted error message if logging is on.
|
static void |
error(java.lang.Throwable t)
Prints an error message for the given Throwable.
|
static void |
error(java.lang.Throwable t,
boolean stackTrace)
Prints an error message for the given Throwable.
|
static boolean |
exitJosm(boolean exit,
int exitCode)
Closes JOSM and optionally terminates the Java Virtual Machine (JVM).
|
private static void |
fireProjectionChanged(Projection oldValue,
Projection newValue,
Bounds oldBounds) |
Layer |
getActiveLayer()
Returns the currently active layer
|
static java.lang.String |
getBaseBrowseUrl()
Replies the base URL for browsing information about a primitive.
|
static java.lang.String |
getBaseUserUrl()
Replies the base URL for browsing information about a user.
|
DataSet |
getCurrentDataSet()
Replies the current data set.
|
OsmDataLayer |
getEditLayer()
Replies the current edit layer
|
static java.lang.String |
getErrorMessage(java.lang.Throwable t)
Returns a human-readable message of error, also usable for developers.
|
java.util.Collection<OsmPrimitive> |
getInProgressSelection()
Replies the current selected primitives, from a end-user point of view.
|
static java.lang.String |
getJOSMWebsite()
Returns the JOSM website URL.
|
static java.util.Collection<java.lang.String> |
getLastErrorAndWarnings()
Replies the first lines of last 10 error and warning messages, used for bug reports
|
static java.util.Map<java.lang.String,java.lang.Throwable> |
getNetworkErrors()
Returns the network errors that occured until now.
|
static java.util.Set<OnlineResource> |
getOfflineResources()
Replies the set of online resources currently offline.
|
static java.lang.String |
getOSMWebsite()
Returns the OSM website URL.
|
static Projection |
getProjection()
Replies the current projection.
|
static javax.swing.Action |
getRegisteredActionShortcut(Shortcut shortcut)
Replies the registered action for the given shortcut
|
static java.lang.String |
getXMLBase()
Returns the JOSM XML URL.
|
boolean |
hasEditLayer()
Replies
true if there is an edit layer |
static void |
info(java.lang.String msg)
Prints an informational message if logging is on.
|
static void |
info(java.lang.String msg,
java.lang.Object... objects)
Prints a formatted informational message if logging is on.
|
static void |
initApplicationPreferences()
Initializes
Main.pref in normal application context. |
static boolean |
isDebugEnabled()
Determines if debug log level is enabled.
|
static boolean |
isDisplayingMapView()
Replies true if JOSM currently displays a map view.
|
static boolean |
isJava8orLater()
Determines if JOSM currently runs with Java 8 or later.
|
static boolean |
isOffline(OnlineResource r)
Determines if the given online resource is currently offline.
|
static boolean |
isPlatformOsx()
Determines if we are currently running on OSX.
|
static boolean |
isPlatformWindows()
Determines if we are currently running on Windows.
|
static boolean |
isTraceEnabled()
Determines if trace log level is enabled.
|
private static Main.DownloadParamType |
paramType(java.lang.String s)
Guess the type of a parameter string specified on the command line with --download= or --downloadgps.
|
protected static void |
postConstructorProcessCmdLine(java.util.Map<MainApplication.Option,java.util.Collection<java.lang.String>> args) |
static void |
preConstructorInit(java.util.Map<MainApplication.Option,java.util.Collection<java.lang.String>> args)
Should be called before the main constructor to setup some parameter stuff
|
static void |
redirectToMainContentPane(javax.swing.JComponent source) |
static void |
registerActionShortcut(javax.swing.Action action,
Shortcut shortcut) |
static void |
registerActionShortcut(JosmAction action) |
private static void |
rememberWarnErrorMsg(java.lang.String msg) |
void |
removeLayer(Layer layer)
Remove the specified layer from the map.
|
static boolean |
removeMapFrameListener(MapFrameListener listener)
Unregisters the given
MapFrameListener from MapFrame changes |
static void |
removeProjectionChangeListener(ProjectionChangeListener listener)
Removes a projection change listener.
|
static void |
removeWindowSwitchListener(Main.WindowSwitchListener listener)
Removes a window switch listener.
|
static boolean |
saveUnsavedModifications()
Asks user to perform "save layer" operations (save on disk and/or upload data to server) for all
AbstractModifiableLayer before JOSM exits. |
static boolean |
saveUnsavedModifications(java.lang.Iterable<? extends Layer> selectedLayers,
boolean exit)
Asks user to perform "save layer" operations (save on disk and/or upload data to server) before data layers deletion.
|
static void |
setInitStatusListener(Main.InitStatusListener listener) |
void |
setMapFrame(MapFrame map)
Set or clear (if passed
null ) the map. |
static boolean |
setOffline(OnlineResource r)
Sets the given online resource to offline state.
|
static void |
setProjection(Projection p)
Sets the current projection
|
static void |
trace(java.lang.String msg)
Prints a trace message if logging is on.
|
static void |
trace(java.lang.String msg,
java.lang.Object... objects)
Prints a formatted trace message if logging is on.
|
static void |
unregisterActionShortcut(javax.swing.Action action,
Shortcut shortcut) |
static void |
unregisterActionShortcut(JosmAction action) |
static void |
unregisterShortcut(Shortcut shortcut) |
static void |
warn(java.lang.String msg)
Prints a warning message if logging is on.
|
static void |
warn(java.lang.String msg,
java.lang.Object... objects)
Prints a formatted warning message if logging is on.
|
static void |
warn(java.lang.Throwable t)
Prints a warning message for the given Throwable.
|
static void |
warn(java.lang.Throwable t,
boolean stackTrace)
Prints a warning message for the given Throwable.
|
private static final java.lang.String JOSM_WEBSITE
private static final java.lang.String OSM_WEBSITE
public static java.awt.Component parent
public static java.lang.String[] commandLineArgs
public static final java.util.concurrent.ExecutorService worker
public static Preferences pref
public static final PrimitiveDeepCopy pasteBuffer
public static Layer pasteSource
pasteBuffer
data comes from.public static MapFrame map
setMapFrame(org.openstreetmap.josm.gui.MapFrame)
to set or clear it.public static ToolbarPreferences toolbar
public final UndoRedoHandler undoRedo
public static PleaseWaitProgressMonitor currentProgressMonitor
public OsmValidator validator
public static final FileWatcher fileWatcher
public final GettingStarted gettingStarted
private static final java.util.Collection<MapFrameListener> mapFrameListeners
protected static final java.util.Map<java.lang.String,java.lang.Throwable> NETWORK_ERRORS
private static final java.util.List<java.lang.String> ERRORS_AND_WARNINGS
private static final java.util.Set<OnlineResource> OFFLINE_RESOURCES
public static int logLevel
public static PlatformHook platform
public static boolean isOpenjdk
private static Main.InitStatusListener initListener
protected static final javax.swing.JPanel contentPanePrivate
public static final javax.swing.JPanel panel
protected static WindowGeometry geometry
protected static int windowState
private final OsmDataLayer.CommandQueueListener redoUndoListener
private static Projection proj
getProjection()
and setProjection(Projection)
for access.
Use setProjection(Projection)
in order to trigger a projection change event.private static final java.util.List<java.lang.ref.WeakReference<ProjectionChangeListener>> listeners
private static final java.util.List<java.lang.ref.WeakReference<Main.WindowSwitchListener>> windowSwitchListeners
public Main()
Main
object. A lot of global variables are initialized here.public static boolean isDisplayingMapView()
true
if JOSM currently displays a map viewprivate static void rememberWarnErrorMsg(java.lang.String msg)
public static final java.util.Collection<java.lang.String> getLastErrorAndWarnings()
public static void error(java.lang.String msg)
msg
- The message to print.public static void warn(java.lang.String msg)
msg
- The message to print.public static void info(java.lang.String msg)
msg
- The message to print.public static void debug(java.lang.String msg)
msg
- The message to print.public static void trace(java.lang.String msg)
msg
- The message to print.public static boolean isDebugEnabled()
true
if log level is at least debug, false
otherwisepublic static boolean isTraceEnabled()
true
if log level is at least trace, false
otherwisepublic static void error(java.lang.String msg, java.lang.Object... objects)
MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
function to format text.msg
- The formatted message to print.objects
- The objects to insert into format string.public static void warn(java.lang.String msg, java.lang.Object... objects)
MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
function to format text.msg
- The formatted message to print.objects
- The objects to insert into format string.public static void info(java.lang.String msg, java.lang.Object... objects)
MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
function to format text.msg
- The formatted message to print.objects
- The objects to insert into format string.public static void debug(java.lang.String msg, java.lang.Object... objects)
MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
function to format text.msg
- The formatted message to print.objects
- The objects to insert into format string.public static void trace(java.lang.String msg, java.lang.Object... objects)
MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
function to format text.msg
- The formatted message to print.objects
- The objects to insert into format string.public static void error(java.lang.Throwable t)
t
- The throwable object causing the errorpublic static void warn(java.lang.Throwable t)
t
- The throwable object causing the errorpublic static void error(java.lang.Throwable t, boolean stackTrace)
t
- The throwable object causing the errorstackTrace
- true
, if the stacktrace should be displayedpublic static void warn(java.lang.Throwable t, boolean stackTrace)
t
- The throwable object causing the errorstackTrace
- true
, if the stacktrace should be displayedpublic static java.lang.String getErrorMessage(java.lang.Throwable t)
t
- The errorpublic static void initApplicationPreferences()
Main.pref
in normal application context.public final void setMapFrame(MapFrame map)
null
) the map.map
- The map to set map
to. Can be null.public final void removeLayer(Layer layer)
layer
- The layer to removepublic static void setInitStatusListener(Main.InitStatusListener listener)
public final void addLayer(Layer layer)
layer
- the layeraddLayer(Layer, ProjectionBounds)
,
addLayer(Layer, ViewportData)
public final void addLayer(Layer layer, ProjectionBounds bounds)
layer
- the layerbounds
- the bounds of the layer (target zoom area); can be null, then
the viewport isn't changedpublic final void addLayer(Layer layer, ViewportData viewport)
layer
- the layerviewport
- the viewport to zoom to; can be null, then the viewport
isn't changedpublic void createMapFrame(Layer firstLayer, ViewportData viewportData)
public boolean hasEditLayer()
true
if there is an edit layertrue
if there is an edit layerpublic OsmDataLayer getEditLayer()
null
, if no current edit layer existspublic DataSet getCurrentDataSet()
null
, if no current data set existspublic java.util.Collection<OsmPrimitive> getInProgressSelection()
DataSet.getSelected()
.
Indeed, if the user is currently in drawing mode, only the way currently being drawn is returned,
see DrawAction.getInProgressSelection()
.null
.public Layer getActiveLayer()
null
, if currently no active layer existspublic static void redirectToMainContentPane(javax.swing.JComponent source)
public static void registerActionShortcut(JosmAction action)
public static void registerActionShortcut(javax.swing.Action action, Shortcut shortcut)
public static void unregisterShortcut(Shortcut shortcut)
public static void unregisterActionShortcut(JosmAction action)
public static void unregisterActionShortcut(javax.swing.Action action, Shortcut shortcut)
public static javax.swing.Action getRegisteredActionShortcut(Shortcut shortcut)
shortcut
- The shortcut to look forpublic static void preConstructorInit(java.util.Map<MainApplication.Option,java.util.Collection<java.lang.String>> args)
args
- The parsed argument list.protected static void postConstructorProcessCmdLine(java.util.Map<MainApplication.Option,java.util.Collection<java.lang.String>> args)
public static boolean saveUnsavedModifications()
AbstractModifiableLayer
before JOSM exits.true
if there was nothing to save, or if the user wants to proceed to save operations. false
if the user cancels.public static boolean saveUnsavedModifications(java.lang.Iterable<? extends Layer> selectedLayers, boolean exit)
selectedLayers
- The layers to check. Only instances of AbstractModifiableLayer
are considered.exit
- true
if JOSM is exiting, false
otherwise.true
if there was nothing to save, or if the user wants to proceed to save operations. false
if the user cancels.public static boolean exitJosm(boolean exit, int exitCode)
exit
- If true
, the JVM is terminated by running System.exit(int)
with a given return code.exitCode
- The return codetrue
if JOSM has been closed, false
if the user has cancelled the operation.private static Main.DownloadParamType paramType(java.lang.String s)
s
- A parameter stringprivate static void downloadFromParamHttp(boolean rawGps, java.lang.String s)
rawGps
- Flag to download raw GPS trackss
- The URL parameterprivate static void downloadFromParamBounds(boolean rawGps, java.lang.String s)
rawGps
- Flag to download raw GPS trackss
- The bounds parameterprivate static void downloadFromParamBounds(boolean rawGps, Bounds b)
rawGps
- Flag to download raw GPS tracksb
- The bounds valuedownloadFromParamBounds(boolean, String)
,
downloadFromParamHttp(boolean, java.lang.String)
public static void determinePlatformHook()
protected static void addListener()
public static boolean isJava8orLater()
true
if the current JVM is at least Java 8, false
otherwisepublic static void checkJavaVersion()
public static Projection getProjection()
public static void setProjection(Projection p)
p
- the projectionprivate static void fireProjectionChanged(Projection oldValue, Projection newValue, Bounds oldBounds)
public static void addProjectionChangeListener(ProjectionChangeListener listener)
listener
- the listener. Ignored if null
.public static void removeProjectionChangeListener(ProjectionChangeListener listener)
listener
- the listener. Ignored if null
.public static void addWindowSwitchListener(Main.WindowSwitchListener listener)
listener
- the listener. Ignored if null
.public static void removeWindowSwitchListener(Main.WindowSwitchListener listener)
listener
- the listener. Ignored if null
.public static boolean addMapFrameListener(MapFrameListener listener, boolean fireWhenMapViewPresent)
MapFrameListener
that will be notified of MapFrame changeslistener
- The MapFrameListenerfireWhenMapViewPresent
- If true, will fire an initial mapFrameInitialized event
when the MapFrame is present. Otherwise will only fire when the MapFrame is created
or destroyed.true
if the listeners collection changed as a result of the callpublic static boolean addMapFrameListener(MapFrameListener listener)
MapFrameListener
that will be notified of MapFrame changeslistener
- The MapFrameListenertrue
if the listeners collection changed as a result of the callpublic static boolean removeMapFrameListener(MapFrameListener listener)
MapFrameListener
from MapFrame changeslistener
- The MapFrameListenertrue
if the listeners collection changed as a result of the callpublic static java.lang.Throwable addNetworkError(java.net.URL url, java.lang.Throwable t)
url
- The accessed URL that caused the errort
- The network errornull
public static java.lang.Throwable addNetworkError(java.lang.String url, java.lang.Throwable t)
url
- The accessed URL that caused the errort
- The network errornull
public static java.util.Map<java.lang.String,java.lang.Throwable> getNetworkErrors()
public static java.lang.String getJOSMWebsite()
public static java.lang.String getXMLBase()
public static java.lang.String getOSMWebsite()
public static java.lang.String getBaseBrowseUrl()
public static java.lang.String getBaseUserUrl()
public static boolean isPlatformOsx()
true
if we are currently running on OSXpublic static boolean isPlatformWindows()
true
if we are currently running on Windowspublic static boolean isOffline(OnlineResource r)
r
- the online resourcetrue
if r
is offline and should not be accessedpublic static boolean setOffline(OnlineResource r)
r
- the online resourcetrue
if r
was not already offlinepublic static java.util.Set<OnlineResource> getOfflineResources()