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 classGpxLayer.CombineTracksToSegmentedTrackActionAction to merge tracks into a single segmented trackstatic classGpxLayer.SplitTrackSegmentsToTracksActionAction to split track segments into a multiple tracks with one segment eachstatic classGpxLayer.SplitTracksToLayersActionAction 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 IGpxTrackSegmentcurrentSegmentCurrent segment forJumpToMarkerActions.JumpToMarkerLayer.GpxDatadataGPX dataprivate GpxData.GpxDataChangeListenerdataChangeListenerAdded as field to be kept as reference.private booleanisExpertModeprivate booleanisLocalFileprivate MarkerLayerlinkedMarkerLayerThe MarkerLayer imported from the same file.boolean[]trackVisibilityused byChooseTrackVisibilityActionto 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 newGpxLayerwithout name.GpxLayer(GpxData d, java.lang.String name)Constructs a newGpxLayerwith a given name.GpxLayer(GpxData d, java.lang.String name, boolean isLocal)Constructs a newGpxLayerwith 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 booleancheckSaveConditions()Checks whether it is ok to launch a save (whether we have data, there is no conflict etc.)java.io.FilecreateAndOpenSaveFileChooser()Creates a new "Save" dialog for this layer and makes it visible.protected MapViewPaintable.LayerPaintercreateMapViewPainter(MapViewPaintable.MapViewEvent event)Creates a new LayerPainter.voiddestroy()Called, when the layer is removed from the mapview and is going to be destroyed.voidexpertChanged(boolean isExpert)The expert mode changed.private voidfillDataInfoComponent(java.lang.StringBuilder info)private voidfillDataToolTipText(java.lang.StringBuilder info)voidfilterTracksByDate(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.FilegetAssociatedFile()Gets the associated file for this layer.java.lang.StringgetChangesetSourceTag()Get the source for the layerjava.awt.ColorgetColor()Return the current color of the layerDatagetData()Get the data for the modifiable layerLayerPositionStrategygetDefaultLayerPosition()Gets the strategy that specifies where this layer should be inserted in a layer list.GpxDatagetGpxData()Returns the GPX data.javax.swing.IcongetIcon()Return a representative small image for this layer.java.lang.ObjectgetInfoComponent()Gets the layer information to display to the user.java.lang.StringgetLabel()Replies a label for this layer useful for UI elements.MarkerLayergetLinkedMarkerLayer()Returns the linked MarkerLayer.javax.swing.Action[]getMenuEntries()Returns list of actions.static java.lang.StringgetTimespanForTrack(IGpxTrack trk)Returns a human readable string that shows the timespan of the given trackjava.lang.StringgetToolTipText()Returns a small tooltip hint about some statistics for this layer.booleanhasColor()Determines whether the layer has / can handle colors.booleanisInfoResizable()Determines if info dialog can be resized (false by default).booleanisLocalFile()Determines if data is attached to a local file.booleanisMergable(Layer other)Determines if the other layer can be merged into this layer.booleanisModified()Determines if data managed by this layer has been modified.booleanisSavable()Replies the savable state of this layer (i.e., if it can be saved through a "File → Save" dialog).private voidjumpToNext(java.util.List<IGpxTrackSegment> segments)voidjumpToNextMarker()Jump (move the viewport) to the next track segment.voidjumpToPreviousMarker()Jump (move the viewport) to the previous track segment.voidmergeFrom(GpxLayer from, boolean cutOverlapping, boolean connect)Merges the given GpxLayer into this layer and can remove timewise overlapping parts of the given trackvoidmergeFrom(Layer from)Merges the given layer into this layer.voidonPostSaveToFile()Initializes the layer after a successful save of data to a file.voidpaint(java.awt.Graphics2D g, MapView mv, Bounds bbox)Paint the dataset using the engine set.voidprojectionChanged(Projection oldValue, Projection newValue)booleanrequiresSaveToFile()Determines if the data managed by this layer needs to be saved to a file.voidsetAssociatedFile(java.io.File file)Sets the associated file for this layer.voidsetColor(java.awt.Color color)Sets the color for this layer.voidsetLinkedMarkerLayer(MarkerLayer linkedMarkerLayer)Sets the linked MarkerLayer.voidvisitBoundingBox(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 byChooseTrackVisibilityActionto 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:LayerReturn the current color of the layer
-
setColor
public void setColor(java.awt.Color color)
Description copied from class:LayerSets the color for this layer. Nothing happens if not supported by the layer
-
hasColor
public boolean hasColor()
Description copied from class:LayerDetermines 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:LayerReturn 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:LayerGets 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:
getInfoComponentin classLayer- Returns:
- Either a String or a
Componentdescribing the layer.
-
fillDataInfoComponent
private void fillDataInfoComponent(java.lang.StringBuilder info)
-
isInfoResizable
public boolean isInfoResizable()
Description copied from class:LayerDetermines if info dialog can be resized (false by default).- Overrides:
isInfoResizablein classLayer- Returns:
trueif the info dialog can be resized,falseotherwise
-
getMenuEntries
public javax.swing.Action[] getMenuEntries()
Description copied from class:LayerReturns 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.INSTANCEinstead of new JSeparator- Specified by:
getMenuEntriesin classLayer- Returns:
- menu actions for this layer
-
isLocalFile
public boolean isLocalFile()
Determines if data is attached to a local file.- Returns:
trueif data is attached to a local file,falseotherwise
-
getToolTipText
public java.lang.String getToolTipText()
Description copied from class:LayerReturns a small tooltip hint about some statistics for this layer.- Specified by:
getToolTipTextin 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:LayerDetermines if the other layer can be merged into this layer.- Specified by:
isMergablein 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:LayerMerges 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:LayerReplies a label for this layer useful for UI elements. Defaults to the layer name
-
visitBoundingBox
public void visitBoundingBox(BoundingXYVisitor v)
Description copied from class:LayerVisits 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:
visitBoundingBoxin classLayer- Parameters:
v- The visitor that gets notified about the contents of this layer.
-
getAssociatedFile
public java.io.File getAssociatedFile()
Description copied from class:LayerGets the associated file for this layer.- Overrides:
getAssociatedFilein classLayer- Returns:
- The file or
nullif it is unset. - See Also:
Layer.setAssociatedFile(File)
-
setAssociatedFile
public void setAssociatedFile(java.io.File file)
Description copied from class:LayerSets the associated file for this layer.The associated file might be the one that the user opened.
- Overrides:
setAssociatedFilein 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:
projectionChangedin interfaceProjectionChangeListener- Overrides:
projectionChangedin classLayer
-
isSavable
public boolean isSavable()
Description copied from class:LayerReplies the savable state of this layer (i.e., if it can be saved through a "File → Save" dialog).- Specified by:
isSavablein interfaceSaveToFile- Overrides:
isSavablein classLayer- Returns:
- true if this layer can be saved to a file
-
checkSaveConditions
public boolean checkSaveConditions()
Description copied from class:LayerChecks whether it is ok to launch a save (whether we have data, there is no conflict etc.)- Overrides:
checkSaveConditionsin classLayer- Returns:
true, if it is safe to save.
-
createAndOpenSaveFileChooser
public java.io.File createAndOpenSaveFileChooser()
Description copied from class:LayerCreates 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:
createAndOpenSaveFileChooserin 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:LayerGets the strategy that specifies where this layer should be inserted in a layer list.- Overrides:
getDefaultLayerPositionin classLayer- Returns:
- That strategy.
-
paint
public void paint(java.awt.Graphics2D g, MapView mv, Bounds bbox)
Description copied from interface:MapViewPaintablePaint the dataset using the engine set.- Specified by:
paintin 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:AbstractMapViewPaintableCreates a new LayerPainter.- Overrides:
createMapViewPainterin classAbstractMapViewPaintable- Parameters:
event- The event that triggered the creation.- Returns:
- The painter.
-
expertChanged
public void expertChanged(boolean isExpert)
Description copied from interface:ExpertToggleAction.ExpertModeChangeListenerThe expert mode changed.- Specified by:
expertChangedin interfaceExpertToggleAction.ExpertModeChangeListener- Parameters:
isExpert-trueif expert mode was enabled, false otherwise.
-
isModified
public boolean isModified()
Description copied from class:AbstractModifiableLayerDetermines if data managed by this layer has been modified.- Specified by:
isModifiedin classAbstractModifiableLayer- Returns:
- true if data has been modified; false, otherwise
-
requiresSaveToFile
public boolean requiresSaveToFile()
Description copied from interface:SaveToFileDetermines 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:
requiresSaveToFilein interfaceSaveToFile- Overrides:
requiresSaveToFilein classAbstractModifiableLayer- Returns:
trueif the data managed by this layer needs to be saved to a file;false, otherwise
-
onPostSaveToFile
public void onPostSaveToFile()
Description copied from interface:SaveToFileInitializes the layer after a successful save of data to a file.- Specified by:
onPostSaveToFilein interfaceSaveToFile- Overrides:
onPostSaveToFilein classAbstractModifiableLayer
-
getChangesetSourceTag
public java.lang.String getChangesetSourceTag()
Description copied from class:LayerGet the source for the layer- Overrides:
getChangesetSourceTagin classLayer- Returns:
- The string for the changeset source tag or
null
-
getData
public Data getData()
Description copied from class:AbstractModifiableLayerGet the data for the modifiable layer- Overrides:
getDatain classAbstractModifiableLayer- Returns:
- The data object
-
getGpxData
public GpxData getGpxData()
Description copied from interface:GpxDataContainerReturns the GPX data.- Specified by:
getGpxDatain interfaceGpxDataContainer- Returns:
- the GPX data
-
jumpToNextMarker
public void jumpToNextMarker()
Jump (move the viewport) to the next track segment.- Specified by:
jumpToNextMarkerin interfaceJumpToMarkerActions.JumpToMarkerLayer
-
jumpToPreviousMarker
public void jumpToPreviousMarker()
Jump (move the viewport) to the previous track segment.- Specified by:
jumpToPreviousMarkerin interfaceJumpToMarkerActions.JumpToMarkerLayer
-
jumpToNext
private void jumpToNext(java.util.List<IGpxTrackSegment> segments)
-
destroy
public void destroy()
Description copied from class:LayerCalled, 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:
destroyin interfaceDestroyable- Overrides:
destroyin classLayer
-
-