public abstract class Main extends Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
Main.DownloadParamType
The type of a command line parameter, to be used in switch statements.
|
private static 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 |
---|---|
protected static List<String> |
COMMAND_LINE_ARGS
Command-line arguments used to run the application.
|
protected static JPanel |
contentPanePrivate |
static PleaseWaitProgressMonitor |
currentProgressMonitor
The progress monitor being currently displayed.
|
private static List<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 String |
JOSM_WEBSITE
The JOSM website URL.
|
private static List<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 Collection<MapFrameListener> |
mapFrameListeners |
MainMenu |
menu
The main menu bar at top of screen.
|
protected static Map<String,Throwable> |
NETWORK_ERRORS |
private static Set<OnlineResource> |
OFFLINE_RESOURCES |
private static String |
OSM_WEBSITE
The OSM website URL.
|
static JPanel |
panel
Global panel.
|
static 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 List<WeakReference<Main.WindowSwitchListener>> |
windowSwitchListeners |
static 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 Throwable |
addNetworkError(String url,
Throwable t)
Adds a new network error that occur to give a hint about broken Internet connection.
|
static Throwable |
addNetworkError(URL url,
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.
|
static void |
clearLastErrorAndWarnings()
Clears the list of last error and warning messages.
|
void |
createMapFrame(Layer firstLayer,
ViewportData viewportData) |
static void |
debug(String msg)
Prints a debug message if logging is on.
|
static void |
debug(String msg,
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.
|
static void |
error(String msg)
Prints an error message if logging is on.
|
static void |
error(String msg,
Object... objects)
Prints a formatted error message if logging is on.
|
static void |
error(Throwable t)
Prints an error message for the given Throwable.
|
static void |
error(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 String |
getBaseBrowseUrl()
Replies the base URL for browsing information about a primitive.
|
static String |
getBaseUserUrl()
Replies the base URL for browsing information about a user.
|
static List<String> |
getCommandLineArgs()
Returns the command-line arguments used to run the application.
|
DataSet |
getCurrentDataSet()
Replies the current data set.
|
OsmDataLayer |
getEditLayer()
Replies the current edit layer
|
static String |
getErrorMessage(Throwable t)
Returns a human-readable message of error, also usable for developers.
|
Collection<OsmPrimitive> |
getInProgressSelection()
Replies the current selected primitives, from a end-user point of view.
|
static String |
getJOSMWebsite()
Returns the JOSM website URL.
|
static Collection<String> |
getLastErrorAndWarnings()
Replies the first lines of last 5 error and warning messages, used for bug reports
|
static Map<String,Throwable> |
getNetworkErrors()
Returns the network errors that occured until now.
|
static Set<OnlineResource> |
getOfflineResources()
Replies the set of online resources currently offline.
|
static String |
getOSMWebsite()
Returns the OSM website URL.
|
static Projection |
getProjection()
Replies the current projection.
|
static Action |
getRegisteredActionShortcut(Shortcut shortcut)
Replies the registered action for the given shortcut
|
static String |
getXMLBase()
Returns the JOSM XML URL.
|
boolean |
hasEditLayer()
Replies
true if there is an edit layer |
static void |
info(String msg)
Prints an informational message if logging is on.
|
static void |
info(String msg,
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.
|
protected static void |
postConstructorProcessCmdLine(Map<MainApplication.Option,Collection<String>> args) |
static void |
preConstructorInit(Map<MainApplication.Option,Collection<String>> args)
Should be called before the main constructor to setup some parameter stuff
|
static void |
redirectToMainContentPane(JComponent source) |
static void |
registerActionShortcut(Action action,
Shortcut shortcut) |
static void |
registerActionShortcut(JosmAction action) |
private static void |
rememberWarnErrorMsg(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(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 boolean |
setOnline(OnlineResource r)
Sets the given online resource to online state.
|
static void |
setProjection(Projection p)
Sets the current projection
|
static void |
trace(String msg)
Prints a trace message if logging is on.
|
static void |
trace(String msg,
Object... objects)
Prints a formatted trace message if logging is on.
|
static void |
unregisterActionShortcut(Action action,
Shortcut shortcut) |
static void |
unregisterActionShortcut(JosmAction action) |
static void |
unregisterShortcut(Shortcut shortcut) |
static void |
warn(String msg)
Prints a warning message if logging is on.
|
static void |
warn(String msg,
Object... objects)
Prints a formatted warning message if logging is on.
|
static void |
warn(Throwable t)
Prints a warning message for the given Throwable.
|
static void |
warn(Throwable t,
boolean stackTrace)
Prints a warning message for the given Throwable.
|
private static final String JOSM_WEBSITE
private static final String OSM_WEBSITE
protected static final List<String> COMMAND_LINE_ARGS
public static final 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 volatile 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 Collection<MapFrameListener> mapFrameListeners
protected static final Map<String,Throwable> NETWORK_ERRORS
private static final List<String> ERRORS_AND_WARNINGS
private static final Set<OnlineResource> OFFLINE_RESOURCES
public static int logLevel
public static volatile PlatformHook platform
public static boolean isOpenjdk
private static volatile Main.InitStatusListener initListener
protected static final JPanel contentPanePrivate
protected static volatile WindowGeometry geometry
protected static int windowState
private final OsmDataLayer.CommandQueueListener redoUndoListener
private static volatile Projection proj
getProjection()
and setProjection(Projection)
for access.
Use setProjection(Projection)
in order to trigger a projection change event.private static final List<WeakReference<ProjectionChangeListener>> listeners
private static final List<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(String msg)
public static final Collection<String> getLastErrorAndWarnings()
public static void clearLastErrorAndWarnings()
public static void error(String msg)
msg
- The message to print.public static void warn(String msg)
msg
- The message to print.public static void info(String msg)
msg
- The message to print.public static void debug(String msg)
msg
- The message to print.public static void trace(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(String msg, 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(String msg, 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(String msg, 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(String msg, 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(String msg, 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(Throwable t)
t
- The throwable object causing the errorpublic static void warn(Throwable t)
t
- The throwable object causing the errorpublic static void error(Throwable t, boolean stackTrace)
t
- The throwable object causing the errorstackTrace
- true
, if the stacktrace should be displayedpublic static void warn(Throwable t, boolean stackTrace)
t
- The throwable object causing the errorstackTrace
- true
, if the stacktrace should be displayedpublic static String getErrorMessage(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 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(JComponent source)
public static void registerActionShortcut(JosmAction action)
public static void registerActionShortcut(Action action, Shortcut shortcut)
public static void unregisterShortcut(Shortcut shortcut)
public static void unregisterActionShortcut(JosmAction action)
public static void unregisterActionShortcut(Action action, Shortcut shortcut)
public static Action getRegisteredActionShortcut(Shortcut shortcut)
shortcut
- The shortcut to look forpublic static void preConstructorInit(Map<MainApplication.Option,Collection<String>> args)
args
- The parsed argument list.protected static void postConstructorProcessCmdLine(Map<MainApplication.Option,Collection<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(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 void downloadFromParamBounds(boolean rawGps, Bounds b)
rawGps
- Flag to download raw GPS tracksb
- The bounds valuepublic 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 Throwable addNetworkError(URL url, Throwable t)
url
- The accessed URL that caused the errort
- The network errornull
public static Throwable addNetworkError(String url, Throwable t)
url
- The accessed URL that caused the errort
- The network errornull
public static Map<String,Throwable> getNetworkErrors()
public static List<String> getCommandLineArgs()
public static String getJOSMWebsite()
public static String getXMLBase()
public static String getOSMWebsite()
public static String getBaseBrowseUrl()
public static 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 boolean setOnline(OnlineResource r)
r
- the online resourcetrue
if r
was offlinepublic static Set<OnlineResource> getOfflineResources()