Package org.openstreetmap.josm.gui.layer
Class GpxLayer
- java.lang.Object
-
- org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable
-
- org.openstreetmap.josm.gui.layer.Layer
-
- org.openstreetmap.josm.gui.layer.AbstractModifiableLayer
-
- org.openstreetmap.josm.gui.layer.GpxLayer
-
- All Implemented Interfaces:
ExpertToggleAction.ExpertModeChangeListener
,GpxDataContainer
,Lockable
,ProjectionChangeListener
,DownloadFromServer
,JumpToMarkerActions.JumpToMarkerLayer
,MapViewPaintable
,SaveToFile
,UploadToServer
,Destroyable
public class GpxLayer extends AbstractModifiableLayer implements GpxDataContainer, ExpertToggleAction.ExpertModeChangeListener, JumpToMarkerActions.JumpToMarkerLayer
A layer that displays data from a Gpx file / the OSM gpx downloads.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GpxLayer.CombineTracksToSegmentedTrackAction
Action to merge tracks into a single segmented trackstatic class
GpxLayer.SplitTrackSegmentsToTracksAction
Action to split track segments into a multiple tracks with one segment eachstatic class
GpxLayer.SplitTracksToLayersAction
Action to split tracks of one gpx layer into multiple gpx layers, the result is one GPX track per gpx layer.-
Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.layer.Layer
Layer.LayerAction, Layer.LayerGpxExportAction, Layer.LayerSaveAction, Layer.LayerSaveAsAction, Layer.MultiLayerAction, Layer.SeparatorLayerAction
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable
AbstractMapViewPaintable.CompatibilityModeLayerPainter
-
Nested classes/interfaces inherited from interface org.openstreetmap.josm.gui.layer.MapViewPaintable
MapViewPaintable.LayerPainter, MapViewPaintable.MapViewEvent, MapViewPaintable.PaintableInvalidationEvent, MapViewPaintable.PaintableInvalidationListener
-
-
Field Summary
Fields Modifier and Type Field Description private IGpxTrackSegment
currentSegment
Current segment forJumpToMarkerActions.JumpToMarkerLayer
.GpxData
data
GPX dataprivate GpxData.GpxDataChangeListener
dataChangeListener
Added as field to be kept as reference.private boolean
isExpertMode
private boolean
isLocalFile
private MarkerLayer
linkedMarkerLayer
The MarkerLayer imported from the same file.boolean[]
trackVisibility
used byChooseTrackVisibilityAction
to determine which tracks to show/hide-
Fields inherited from class org.openstreetmap.josm.gui.layer.AbstractModifiableLayer
IS_DIRTY_SYMBOL, REQUIRES_SAVE_TO_DISK_PROP
-
Fields inherited from class org.openstreetmap.josm.gui.layer.Layer
FILTER_STATE_PROP, NAME_PROP, OPACITY_PROP, propertyChangeSupport, VISIBLE_PROP
-
-
Constructor Summary
Constructors Constructor Description GpxLayer(GpxData d)
Constructs a newGpxLayer
without name.GpxLayer(GpxData d, java.lang.String name)
Constructs a newGpxLayer
with a given name.GpxLayer(GpxData d, java.lang.String name, boolean isLocal)
Constructs a newGpxLayer
with a given name, that can be attached to a local file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkSaveConditions()
Checks whether it is ok to launch a save (whether we have data, there is no conflict etc.)java.io.File
createAndOpenSaveFileChooser()
Creates a new "Save" dialog for this layer and makes it visible.protected MapViewPaintable.LayerPainter
createMapViewPainter(MapViewPaintable.MapViewEvent event)
Creates a new LayerPainter.void
destroy()
Called, when the layer is removed from the mapview and is going to be destroyed.void
expertChanged(boolean isExpert)
The expert mode changed.private void
fillDataInfoComponent(java.lang.StringBuilder info)
private void
fillDataToolTipText(java.lang.StringBuilder info)
void
filterTracksByDate(java.time.Instant fromDate, java.time.Instant toDate, boolean showWithoutDate)
Shows/hides all tracks of a given date range by setting them to visible/invisible.java.io.File
getAssociatedFile()
Gets the associated file for this layer.java.lang.String
getChangesetSourceTag()
Get the source for the layerjava.awt.Color
getColor()
Return the current color of the layerData
getData()
Get the data for the modifiable layerLayerPositionStrategy
getDefaultLayerPosition()
Gets the strategy that specifies where this layer should be inserted in a layer list.GpxData
getGpxData()
Returns the GPX data.javax.swing.Icon
getIcon()
Return a representative small image for this layer.java.lang.Object
getInfoComponent()
Gets the layer information to display to the user.java.lang.String
getLabel()
Replies a label for this layer useful for UI elements.MarkerLayer
getLinkedMarkerLayer()
Returns the linked MarkerLayer.javax.swing.Action[]
getMenuEntries()
Returns list of actions.static java.lang.String
getTimespanForTrack(IGpxTrack trk)
Returns a human readable string that shows the timespan of the given trackjava.lang.String
getToolTipText()
Returns a small tooltip hint about some statistics for this layer.boolean
hasColor()
Determines whether the layer has / can handle colors.boolean
isInfoResizable()
Determines if info dialog can be resized (false by default).boolean
isLocalFile()
Determines if data is attached to a local file.boolean
isMergable(Layer other)
Determines if the other layer can be merged into this layer.boolean
isModified()
Determines if data managed by this layer has been modified.boolean
isSavable()
Replies the savable state of this layer (i.e., if it can be saved through a "File → Save" dialog).private void
jumpToNext(java.util.List<IGpxTrackSegment> segments)
void
jumpToNextMarker()
Jump (move the viewport) to the next track segment.void
jumpToPreviousMarker()
Jump (move the viewport) to the previous track segment.void
mergeFrom(GpxLayer from, boolean cutOverlapping, boolean connect)
Merges the given GpxLayer into this layer and can remove timewise overlapping parts of the given trackvoid
mergeFrom(Layer from)
Merges the given layer into this layer.void
onPostSaveToFile()
Initializes the layer after a successful save of data to a file.void
paint(java.awt.Graphics2D g, MapView mv, Bounds bbox)
Paint the dataset using the engine set.void
projectionChanged(Projection oldValue, Projection newValue)
boolean
requiresSaveToFile()
Determines if the data managed by this layer needs to be saved to a file.void
setAssociatedFile(java.io.File file)
Sets the associated file for this layer.void
setColor(java.awt.Color color)
Sets the color for this layer.void
setLinkedMarkerLayer(MarkerLayer linkedMarkerLayer)
Sets the linked MarkerLayer.void
visitBoundingBox(BoundingXYVisitor v)
Visits the content bounds of this layer.-
Methods inherited from class org.openstreetmap.josm.gui.layer.AbstractModifiableLayer
autosave, createUploadTask, getUploadDialog, isDirty, isDownloadable, isLocked, isUploadable, isUploadDiscouraged, isUploadInProgress, lock, onPostUploadToServer, requiresUploadToServer, unlock
-
Methods inherited from class org.openstreetmap.josm.gui.layer.Layer
addPropertyChangeListener, fireFilterStateChanged, fireOpacityChanged, fireVisibleChanged, getName, getOpacity, getViewProjectionBounds, hookUpMapView, isBackgroundLayer, isProjectionSupported, isRenamed, isVisible, nameSupportedProjections, onPostLoadFromFile, removePropertyChangeListener, rename, setBackgroundLayer, setFilterStateChanged, setName, setOpacity, setVisible, toggleVisible, toString
-
Methods inherited from class org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable
addInvalidationListener, attachToMapView, invalidate, removeInvalidationListener
-
-
-
-
Field Detail
-
isLocalFile
private boolean isLocalFile
-
isExpertMode
private boolean isExpertMode
-
trackVisibility
public boolean[] trackVisibility
used byChooseTrackVisibilityAction
to determine which tracks to show/hideCall
AbstractMapViewPaintable.invalidate()
after each change!TODO: Make it private, make it respond to track changes.
-
dataChangeListener
private final GpxData.GpxDataChangeListener dataChangeListener
Added as field to be kept as reference.
-
linkedMarkerLayer
private MarkerLayer linkedMarkerLayer
The MarkerLayer imported from the same file.
-
currentSegment
private IGpxTrackSegment currentSegment
Current segment forJumpToMarkerActions.JumpToMarkerLayer
.
-
-
Method Detail
-
getColor
public java.awt.Color getColor()
Description copied from class:Layer
Return the current color of the layer
-
setColor
public void setColor(java.awt.Color color)
Description copied from class:Layer
Sets the color for this layer. Nothing happens if not supported by the layer
-
hasColor
public boolean hasColor()
Description copied from class:Layer
Determines whether the layer has / can handle colors.
-
getTimespanForTrack
public static java.lang.String getTimespanForTrack(IGpxTrack trk)
Returns a human readable string that shows the timespan of the given track- Parameters:
trk
- The GPX track for which timespan is displayed- Returns:
- The timespan as a string
-
getIcon
public javax.swing.Icon getIcon()
Description copied from class:Layer
Return a representative small image for this layer. The image must not be larger than 64 pixel in any dimension.
-
getInfoComponent
public java.lang.Object getInfoComponent()
Description copied from class:Layer
Gets the layer information to display to the user. This is used if the user requests information about this layer. It should display a description of the layer content.- Specified by:
getInfoComponent
in classLayer
- Returns:
- Either a String or a
Component
describing the layer.
-
fillDataInfoComponent
private void fillDataInfoComponent(java.lang.StringBuilder info)
-
isInfoResizable
public boolean isInfoResizable()
Description copied from class:Layer
Determines if info dialog can be resized (false by default).- Overrides:
isInfoResizable
in classLayer
- Returns:
true
if the info dialog can be resized,false
otherwise
-
getMenuEntries
public javax.swing.Action[] getMenuEntries()
Description copied from class:Layer
Returns list of actions. Action can implement LayerAction interface when it needs to be represented by other menu component than JMenuItem or when it supports multiple layers. Actions that support multiple layers should also have correct equals implementation.Use
Layer.SeparatorLayerAction.INSTANCE
instead of new JSeparator- Specified by:
getMenuEntries
in classLayer
- Returns:
- menu actions for this layer
-
isLocalFile
public boolean isLocalFile()
Determines if data is attached to a local file.- Returns:
true
if data is attached to a local file,false
otherwise
-
getToolTipText
public java.lang.String getToolTipText()
Description copied from class:Layer
Returns a small tooltip hint about some statistics for this layer.- Specified by:
getToolTipText
in classLayer
- Returns:
- A small tooltip hint about some statistics for this layer.
-
fillDataToolTipText
private void fillDataToolTipText(java.lang.StringBuilder info)
-
isMergable
public boolean isMergable(Layer other)
Description copied from class:Layer
Determines if the other layer can be merged into this layer.- Specified by:
isMergable
in classLayer
- Parameters:
other
- The other layer that is tested to be mergable with this.- Returns:
- Whether the other layer can be merged into this layer.
-
filterTracksByDate
public void filterTracksByDate(java.time.Instant fromDate, java.time.Instant toDate, boolean showWithoutDate)
Shows/hides all tracks of a given date range by setting them to visible/invisible.- Parameters:
fromDate
- The min datetoDate
- The max dateshowWithoutDate
- Include tracks that don't have any date set..
-
mergeFrom
public void mergeFrom(Layer from)
Description copied from class:Layer
Merges the given layer into this layer. Throws if the layer types are incompatible.
-
mergeFrom
public void mergeFrom(GpxLayer from, boolean cutOverlapping, boolean connect)
Merges the given GpxLayer into this layer and can remove timewise overlapping parts of the given track- Parameters:
from
- The GpxLayer that gets merged into this onecutOverlapping
- whether overlapping parts of the given track should be removedconnect
- whether the tracks should be connected on cuts- Since:
- 14338
-
getLabel
public java.lang.String getLabel()
Description copied from class:Layer
Replies a label for this layer useful for UI elements. Defaults to the layer name
-
visitBoundingBox
public void visitBoundingBox(BoundingXYVisitor v)
Description copied from class:Layer
Visits the content bounds of this layer. The behavior of this method depends on the layer, but each implementation should attempt to cover the relevant content of the layer in this method.- Specified by:
visitBoundingBox
in classLayer
- Parameters:
v
- The visitor that gets notified about the contents of this layer.
-
getAssociatedFile
public java.io.File getAssociatedFile()
Description copied from class:Layer
Gets the associated file for this layer.- Overrides:
getAssociatedFile
in classLayer
- Returns:
- The file or
null
if it is unset. - See Also:
Layer.setAssociatedFile(File)
-
setAssociatedFile
public void setAssociatedFile(java.io.File file)
Description copied from class:Layer
Sets the associated file for this layer.The associated file might be the one that the user opened.
- Overrides:
setAssociatedFile
in classLayer
- Parameters:
file
- The file, may benull
-
getLinkedMarkerLayer
public MarkerLayer getLinkedMarkerLayer()
Returns the linked MarkerLayer.- Returns:
- the linked MarkerLayer (imported from the same file)
- Since:
- 15496
-
setLinkedMarkerLayer
public void setLinkedMarkerLayer(MarkerLayer linkedMarkerLayer)
Sets the linked MarkerLayer.- Parameters:
linkedMarkerLayer
- the linked MarkerLayer- Since:
- 15496
-
projectionChanged
public void projectionChanged(Projection oldValue, Projection newValue)
- Specified by:
projectionChanged
in interfaceProjectionChangeListener
- Overrides:
projectionChanged
in classLayer
-
isSavable
public boolean isSavable()
Description copied from class:Layer
Replies the savable state of this layer (i.e., if it can be saved through a "File → Save" dialog).- Specified by:
isSavable
in interfaceSaveToFile
- Overrides:
isSavable
in classLayer
- Returns:
- true if this layer can be saved to a file
-
checkSaveConditions
public boolean checkSaveConditions()
Description copied from class:Layer
Checks whether it is ok to launch a save (whether we have data, there is no conflict etc.)- Overrides:
checkSaveConditions
in classLayer
- Returns:
true
, if it is safe to save.
-
createAndOpenSaveFileChooser
public java.io.File createAndOpenSaveFileChooser()
Description copied from class:Layer
Creates a new "Save" dialog for this layer and makes it visible.When the user has chosen a file, checks the file extension, and confirms overwriting if needed.
- Overrides:
createAndOpenSaveFileChooser
in classLayer
- Returns:
- The output
File
- See Also:
SaveActionBase.createAndOpenSaveFileChooser(java.lang.String, org.openstreetmap.josm.actions.ExtensionFileFilter)
-
getDefaultLayerPosition
public LayerPositionStrategy getDefaultLayerPosition()
Description copied from class:Layer
Gets the strategy that specifies where this layer should be inserted in a layer list.- Overrides:
getDefaultLayerPosition
in classLayer
- Returns:
- That strategy.
-
paint
public void paint(java.awt.Graphics2D g, MapView mv, Bounds bbox)
Description copied from interface:MapViewPaintable
Paint the dataset using the engine set.- Specified by:
paint
in interfaceMapViewPaintable
- Parameters:
g
- Graphicsmv
- The object that can translate GeoPoints to screen coordinates.bbox
- Bounding box
-
createMapViewPainter
protected MapViewPaintable.LayerPainter createMapViewPainter(MapViewPaintable.MapViewEvent event)
Description copied from class:AbstractMapViewPaintable
Creates a new LayerPainter.- Overrides:
createMapViewPainter
in classAbstractMapViewPaintable
- Parameters:
event
- The event that triggered the creation.- Returns:
- The painter.
-
expertChanged
public void expertChanged(boolean isExpert)
Description copied from interface:ExpertToggleAction.ExpertModeChangeListener
The expert mode changed.- Specified by:
expertChanged
in interfaceExpertToggleAction.ExpertModeChangeListener
- Parameters:
isExpert
-true
if expert mode was enabled, false otherwise.
-
isModified
public boolean isModified()
Description copied from class:AbstractModifiableLayer
Determines if data managed by this layer has been modified.- Specified by:
isModified
in classAbstractModifiableLayer
- Returns:
- true if data has been modified; false, otherwise
-
requiresSaveToFile
public boolean requiresSaveToFile()
Description copied from interface:SaveToFile
Determines if the data managed by this layer needs to be saved to a file. Only replies true if a file is assigned to this layer and if the data managed by this layer has been modified since the last save operation to the file.- Specified by:
requiresSaveToFile
in interfaceSaveToFile
- Overrides:
requiresSaveToFile
in classAbstractModifiableLayer
- Returns:
true
if the data managed by this layer needs to be saved to a file;false
, otherwise
-
onPostSaveToFile
public void onPostSaveToFile()
Description copied from interface:SaveToFile
Initializes the layer after a successful save of data to a file.- Specified by:
onPostSaveToFile
in interfaceSaveToFile
- Overrides:
onPostSaveToFile
in classAbstractModifiableLayer
-
getChangesetSourceTag
public java.lang.String getChangesetSourceTag()
Description copied from class:Layer
Get the source for the layer- Overrides:
getChangesetSourceTag
in classLayer
- Returns:
- The string for the changeset source tag or
null
-
getData
public Data getData()
Description copied from class:AbstractModifiableLayer
Get the data for the modifiable layer- Overrides:
getData
in classAbstractModifiableLayer
- Returns:
- The data object
-
getGpxData
public GpxData getGpxData()
Description copied from interface:GpxDataContainer
Returns the GPX data.- Specified by:
getGpxData
in interfaceGpxDataContainer
- Returns:
- the GPX data
-
jumpToNextMarker
public void jumpToNextMarker()
Jump (move the viewport) to the next track segment.- Specified by:
jumpToNextMarker
in interfaceJumpToMarkerActions.JumpToMarkerLayer
-
jumpToPreviousMarker
public void jumpToPreviousMarker()
Jump (move the viewport) to the previous track segment.- Specified by:
jumpToPreviousMarker
in interfaceJumpToMarkerActions.JumpToMarkerLayer
-
jumpToNext
private void jumpToNext(java.util.List<IGpxTrackSegment> segments)
-
destroy
public void destroy()
Description copied from class:Layer
Called, when the layer is removed from the mapview and is going to be destroyed.This is because the Layer constructor cannot add itself safely as a listener to the layerlist dialog, because there may be no such dialog yet (loaded via command line parameter).
- Specified by:
destroy
in interfaceDestroyable
- Overrides:
destroy
in classLayer
-
-