public class OsmDataLayer extends AbstractModifiableLayer implements DataSetListenerAdapter.Listener, SelectionChangedListener
Modifier and Type | Class and Description |
---|---|
static interface |
OsmDataLayer.CommandQueueListener |
private class |
OsmDataLayer.ConsistencyTestAction |
class |
OsmDataLayer.ConvertToGpxLayerAction
Action that converts this OSM layer to a GPX layer.
|
static class |
OsmDataLayer.DataCountVisitor |
static interface |
OsmDataLayer.LayerStateChangeListener
Listener called when a state of this layer has changed.
|
Layer.LayerAction, Layer.LayerGpxExportAction, Layer.LayerSaveAction, Layer.LayerSaveAsAction, Layer.MultiLayerAction, Layer.SeparatorLayerAction
AbstractMapViewPaintable.CompatibilityModeLayerPainter
MapViewPaintable.LayerPainter, MapViewPaintable.MapViewEvent, MapViewPaintable.PaintableInvalidationEvent, MapViewPaintable.PaintableInvalidationListener
Modifier and Type | Field and Description |
---|---|
private ConflictCollection |
conflicts
the collection of conflicts detected in this layer
|
DataSet |
data
The data behind this layer.
|
private static int |
dataLayerCounter
the global counter for created data layers
|
static int |
DEFAULT_RECENT_RELATIONS_NUMBER |
private static java.awt.TexturePaint |
hatched
a paint texture for non-downloaded area
|
private int |
highlightUpdateCount |
private boolean |
isChanged |
private java.util.concurrent.CopyOnWriteArrayList<OsmDataLayer.LayerStateChangeListener> |
layerStateChangeListeners |
static IntegerProperty |
PROPERTY_RECENT_RELATIONS_NUMBER |
static StringProperty |
PROPERTY_SAVE_EXTENSION |
private java.util.Map<Relation,java.lang.Void> |
recentRelations
List of recent relations
|
static java.lang.String |
REQUIRES_SAVE_TO_DISK_PROP
Property used to know if this layer has to be saved on disk
|
static java.lang.String |
REQUIRES_UPLOAD_TO_SERVER_PROP
Property used to know if this layer has to be uploaded
|
private boolean |
requiresSaveToFile |
private boolean |
requiresUploadToServer |
java.util.List<TestError> |
validationErrors
List of validation errors in this layer.
|
FILTER_STATE_PROP, NAME_PROP, OPACITY_PROP, propertyChangeSupport, VISIBLE_PROP
Constructor and Description |
---|
OsmDataLayer(DataSet data,
java.lang.String name,
java.io.File associatedFile)
Construct a new
OsmDataLayer . |
Modifier and Type | Method and Description |
---|---|
private static void |
addDoubleIfPresent(WayPoint wpt,
OsmPrimitive p,
java.lang.String gpxKey,
java.lang.String... osmKeys) |
private static void |
addIntegerIfPresent(WayPoint wpt,
OsmPrimitive p,
java.lang.String gpxKey,
java.lang.String... osmKeys) |
void |
addLayerStateChangeListener(OsmDataLayer.LayerStateChangeListener listener)
Adds a layer state change listener
|
private static void |
addStringIfPresent(WayPoint wpt,
OsmPrimitive p,
java.lang.String gpxKey,
java.lang.String... osmKeys) |
boolean |
checkSaveConditions()
Checks whether it is ok to launch a save (whether we have data, there is no conflict etc.)
|
void |
cleanupAfterUpload(java.util.Collection<? extends IPrimitive> processed)
Clean out the data behind the layer.
|
boolean |
containsPoint(LatLon coor)
Determines if this layer contains data at the given coordinate.
|
java.io.File |
createAndOpenSaveFileChooser()
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 overwrite if needed. |
static void |
createHatchTexture()
Initialize the hatch pattern used to paint the non-downloaded area
|
static java.lang.String |
createNewName()
Replies a new unique name for a data layer
|
AbstractIOTask |
createUploadTask(ProgressMonitor monitor)
Creates a new
AbstractIOTask for uploading data. |
void |
destroy()
Called, when the layer is removed from the mapview and is going to be destroyed.
|
static java.awt.Color |
getBackgroundColor()
Replies background color for downloaded areas.
|
protected ImageProvider |
getBaseIconProvider()
Return the image provider to get the base icon
|
ConflictCollection |
getConflicts()
Replies the set of conflicts currently managed in this layer.
|
javax.swing.Icon |
getIcon()
Return a representative small image for this layer.
|
java.lang.Object |
getInfoComponent() |
javax.swing.Action[] |
getMenuEntries()
Returns list of actions.
|
static java.awt.Color |
getOutsideColor()
Replies background color for non-downloaded areas.
|
java.util.ArrayList<Relation> |
getRecentRelations()
Returns list of recently closed relations or null if none.
|
java.lang.String |
getToolTipText() |
AbstractUploadDialog |
getUploadDialog()
Returns the upload dialog for this layer.
|
ProjectionBounds |
getViewProjectionBounds()
Gets the
ProjectionBounds for this layer to be visible to the user. |
void |
invalidate()
This needs to be called whenever the content of this view was invalidated.
|
boolean |
isChanged()
Check changed status of layer
|
private boolean |
isDataSetEmpty()
Check the data set if it would be empty on save.
|
boolean |
isMergable(Layer other) |
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).
|
boolean |
isUploadable()
Determines if the layer is able to upload data and implements the
UploadToServer interface. |
boolean |
isUploadDiscouraged()
Determines if upload of data managed by this layer is discouraged.
|
void |
mergeFrom(DataSet from)
merges the primitives in dataset
from into the dataset of
this layer |
void |
mergeFrom(DataSet from,
ProgressMonitor progressMonitor)
merges the primitives in dataset
from into the dataset of this layer |
void |
mergeFrom(Layer from)
Merges the given layer into this layer.
|
private static void |
nodesToGpxData(java.util.Collection<Node> nodes,
GpxData gpxData,
java.util.Set<Node> doneNodes) |
private static WayPoint |
nodeToWayPoint(Node n) |
void |
onPostDownloadFromServer()
Actions run after data has been downloaded to this layer.
|
void |
onPostLoadFromFile()
Initializes the layer after a successful load of data from a file
|
void |
onPostSaveToFile()
Initializes the layer after a successful save of data to a file.
|
void |
onPostUploadToServer()
Initializes the layer after a successful upload to the server.
|
void |
paint(java.awt.Graphics2D g,
MapView mv,
Bounds box)
Draw all primitives in this layer but do not draw modified ones (they
are drawn by the edit layer).
|
void |
processDatasetEvent(AbstractDatasetChangedEvent event) |
void |
projectionChanged(Projection oldValue,
Projection newValue) |
void |
removeLayerPropertyChangeListener(OsmDataLayer.LayerStateChangeListener listener)
Deprecated.
Method name contains a typo, use
removeLayerStateChangeListener(LayerStateChangeListener) . |
void |
removeLayerStateChangeListener(OsmDataLayer.LayerStateChangeListener listener)
Removes a layer state change listener
|
void |
removeRecentRelation(Relation relation)
Remove relation from list of recent relations.
|
boolean |
requiresSaveToFile()
Determines if the data managed by this layer needs to be saved to
a file.
|
boolean |
requiresUploadToServer()
Determines if the data managed by this layer needs to be uploaded to
the server because it contains modified data.
|
void |
selectionChanged(java.util.Collection<? extends OsmPrimitive> newSelection)
Informs the listener that the selection in the dataset has changed.
|
void |
setRecentRelation(Relation relation)
Adds recently closed relation.
|
protected void |
setRequiresSaveToFile(boolean newValue) |
protected void |
setRequiresUploadToServer(boolean newValue) |
void |
setUploadDiscouraged(boolean uploadDiscouraged)
Sets the "discouraged upload" flag.
|
GpxData |
toGpxData()
Converts OSM data behind this layer to GPX data.
|
static GpxData |
toGpxData(DataSet data,
java.io.File file)
Converts given OSM dataset to GPX data.
|
void |
visitBoundingBox(BoundingXYVisitor v) |
private static void |
waysToGpxData(java.util.Collection<Way> ways,
GpxData gpxData,
java.util.Set<Node> doneNodes) |
addPropertyChangeListener, checkLayerMemoryDoesNotExceedMaximum, estimateMemoryUsage, fireFilterStateChanged, fireOpacityChanged, fireVisibleChanged, getAssociatedFile, getColor, getDefaultLayerPosition, getName, getOpacity, hookUpMapView, isBackgroundLayer, isInfoResizable, isProjectionSupported, isRenamed, isVisible, nameSupportedProjections, removePropertyChangeListener, rename, setAssociatedFile, setBackgroundLayer, setFilterStateChanged, setName, setOpacity, setVisible, toggleVisible
addInvalidationListener, attachToMapView, createMapViewPainter, removeInvalidationListener
public static final java.lang.String REQUIRES_SAVE_TO_DISK_PROP
public static final java.lang.String REQUIRES_UPLOAD_TO_SERVER_PROP
private boolean requiresSaveToFile
private boolean requiresUploadToServer
private boolean isChanged
private int highlightUpdateCount
public final java.util.List<TestError> validationErrors
public static final int DEFAULT_RECENT_RELATIONS_NUMBER
public static final IntegerProperty PROPERTY_RECENT_RELATIONS_NUMBER
public static final StringProperty PROPERTY_SAVE_EXTENSION
private final java.util.Map<Relation,java.lang.Void> recentRelations
private static int dataLayerCounter
private final java.util.concurrent.CopyOnWriteArrayList<OsmDataLayer.LayerStateChangeListener> layerStateChangeListeners
private final ConflictCollection conflicts
private static volatile java.awt.TexturePaint hatched
public OsmDataLayer(DataSet data, java.lang.String name, java.io.File associatedFile)
OsmDataLayer
.data
- OSM dataname
- Layer nameassociatedFile
- Associated .osm file (can be null)public java.util.ArrayList<Relation> getRecentRelations()
null
if nonepublic void setRecentRelation(Relation relation)
relation
- new entry for the list of recently closed relationspublic void removeRecentRelation(Relation relation)
relation
- relation to removeprotected void setRequiresSaveToFile(boolean newValue)
protected void setRequiresUploadToServer(boolean newValue)
public static java.lang.String createNewName()
public void addLayerStateChangeListener(OsmDataLayer.LayerStateChangeListener listener)
listener
- the listener. Ignored if null or already registered.@Deprecated public void removeLayerPropertyChangeListener(OsmDataLayer.LayerStateChangeListener listener)
removeLayerStateChangeListener(LayerStateChangeListener)
.listener
- the listener. Ignored if null or already registered.public void removeLayerStateChangeListener(OsmDataLayer.LayerStateChangeListener listener)
listener
- the listener. Ignored if null or already registered.public static java.awt.Color getBackgroundColor()
public static java.awt.Color getOutsideColor()
public static void createHatchTexture()
protected ImageProvider getBaseIconProvider()
public javax.swing.Icon getIcon()
Layer
public void paint(java.awt.Graphics2D g, MapView mv, Bounds box)
paint
in interface MapViewPaintable
g
- Graphicsmv
- The object that can translate GeoPoints to screen coordinates.box
- Bounding boxpublic java.lang.String getToolTipText()
getToolTipText
in class Layer
public void mergeFrom(Layer from)
Layer
public void mergeFrom(DataSet from)
from
into the dataset of
this layerfrom
- the source data setpublic void mergeFrom(DataSet from, ProgressMonitor progressMonitor)
from
into the dataset of this layerfrom
- the source data setprogressMonitor
- the progress monitor, can be null
public boolean isMergable(Layer other)
isMergable
in class Layer
other
- The other layer that is tested to be mergable with this.public void visitBoundingBox(BoundingXYVisitor v)
visitBoundingBox
in class Layer
public void cleanupAfterUpload(java.util.Collection<? extends IPrimitive> processed)
processed
- A list of all objects that were actually uploaded.
May be null
, which means nothing has been uploadedpublic java.lang.Object getInfoComponent()
getInfoComponent
in class Layer
public javax.swing.Action[] getMenuEntries()
Layer
Layer.SeparatorLayerAction.INSTANCE
instead of new JSeparatorgetMenuEntries
in class Layer
public static GpxData toGpxData(DataSet data, java.io.File file)
data
- OSM datasetfile
- output .gpx fileprivate static void waysToGpxData(java.util.Collection<Way> ways, GpxData gpxData, java.util.Set<Node> doneNodes)
private static WayPoint nodeToWayPoint(Node n)
private static void nodesToGpxData(java.util.Collection<Node> nodes, GpxData gpxData, java.util.Set<Node> doneNodes)
private static void addIntegerIfPresent(WayPoint wpt, OsmPrimitive p, java.lang.String gpxKey, java.lang.String... osmKeys)
private static void addDoubleIfPresent(WayPoint wpt, OsmPrimitive p, java.lang.String gpxKey, java.lang.String... osmKeys)
private static void addStringIfPresent(WayPoint wpt, OsmPrimitive p, java.lang.String gpxKey, java.lang.String... osmKeys)
public GpxData toGpxData()
public boolean containsPoint(LatLon coor)
coor
- the coordinatetrue
if data sources bounding boxes contain coor
public ConflictCollection getConflicts()
public boolean isUploadable()
AbstractModifiableLayer
UploadToServer
interface.isUploadable
in interface UploadToServer
isUploadable
in class AbstractModifiableLayer
public boolean requiresUploadToServer()
AbstractModifiableLayer
requiresUploadToServer
in interface UploadToServer
requiresUploadToServer
in class AbstractModifiableLayer
public boolean requiresSaveToFile()
AbstractModifiableLayer
requiresSaveToFile
in interface SaveToFile
requiresSaveToFile
in class AbstractModifiableLayer
public void onPostLoadFromFile()
Layer
onPostLoadFromFile
in class Layer
public void onPostDownloadFromServer()
public boolean isChanged()
Layer
public void onPostSaveToFile()
AbstractModifiableLayer
onPostSaveToFile
in interface SaveToFile
onPostSaveToFile
in class AbstractModifiableLayer
public void onPostUploadToServer()
AbstractModifiableLayer
onPostUploadToServer
in interface UploadToServer
onPostUploadToServer
in class AbstractModifiableLayer
public void destroy()
Layer
destroy
in interface Destroyable
destroy
in class Layer
public void processDatasetEvent(AbstractDatasetChangedEvent event)
processDatasetEvent
in interface DataSetListenerAdapter.Listener
public void selectionChanged(java.util.Collection<? extends OsmPrimitive> newSelection)
SelectionChangedListener
selectionChanged
in interface SelectionChangedListener
newSelection
- The new selection.public void invalidate()
AbstractMapViewPaintable
invalidate
in class AbstractMapViewPaintable
public void projectionChanged(Projection oldValue, Projection newValue)
projectionChanged
in interface ProjectionChangeListener
projectionChanged
in class Layer
public final boolean isUploadDiscouraged()
AbstractModifiableLayer
isUploadDiscouraged
in interface UploadToServer
isUploadDiscouraged
in class AbstractModifiableLayer
public final void setUploadDiscouraged(boolean uploadDiscouraged)
uploadDiscouraged
- true
if upload of data managed by this layer is discouraged.
This feature allows to use "private" data layers.public final boolean isModified()
AbstractModifiableLayer
isModified
in class AbstractModifiableLayer
public boolean isSavable()
Layer
isSavable
in interface SaveToFile
isSavable
in class Layer
public boolean checkSaveConditions()
Layer
checkSaveConditions
in class Layer
true
, if it is safe to save.private boolean isDataSetEmpty()
true
, if a save result in an empty data set.public java.io.File createAndOpenSaveFileChooser()
Layer
createAndOpenSaveFileChooser
in class Layer
File
SaveActionBase.createAndOpenSaveFileChooser(java.lang.String, org.openstreetmap.josm.actions.ExtensionFileFilter)
public AbstractIOTask createUploadTask(ProgressMonitor monitor)
AbstractModifiableLayer
AbstractIOTask
for uploading data.createUploadTask
in interface UploadToServer
createUploadTask
in class AbstractModifiableLayer
monitor
- The progress monitorAbstractIOTask
for uploading data, or null
if not applicablepublic AbstractUploadDialog getUploadDialog()
AbstractModifiableLayer
getUploadDialog
in interface UploadToServer
getUploadDialog
in class AbstractModifiableLayer
null
if not applicablepublic ProjectionBounds getViewProjectionBounds()
Layer
ProjectionBounds
for this layer to be visible to the user. This can be the exact bounds, the UI handles padding. Return
null
if you cannot provide this information. The default implementation uses the bounds from
Layer.visitBoundingBox(BoundingXYVisitor)
.getViewProjectionBounds
in class Layer