public class OsmDataLayer extends AbstractOsmDataLayer implements DataSetListenerAdapter.Listener, DataSelectionListener, HighlightUpdateListener
| Modifier and Type | Class and Description |
|---|---|
private class |
OsmDataLayer.ConsistencyTestAction |
class |
OsmDataLayer.ConvertToGpxLayerAction
Action that converts this OSM layer to a GPX layer.
|
static class |
OsmDataLayer.DataCountVisitor
A listener that counts the number of primitives it encounters
|
static interface |
OsmDataLayer.LayerStateChangeListener
Listener called when a state of this layer has changed.
|
(package private) static class |
OsmDataLayer.LruCache |
Layer.LayerAction, Layer.LayerGpxExportAction, Layer.LayerSaveAction, Layer.LayerSaveAsAction, Layer.MultiLayerAction, Layer.SeparatorLayerActionAbstractMapViewPaintable.CompatibilityModeLayerPainterDataSelectionListener.AbstractSelectionEvent, DataSelectionListener.SelectionAddEvent, DataSelectionListener.SelectionChangeEvent, DataSelectionListener.SelectionRemoveEvent, DataSelectionListener.SelectionReplaceEvent, DataSelectionListener.SelectionToggleEventHighlightUpdateListener.HighlightUpdateEventMapViewPaintable.LayerPainter, MapViewPaintable.MapViewEvent, MapViewPaintable.PaintableInvalidationEvent, MapViewPaintable.PaintableInvalidationListener| Modifier and Type | Field and Description |
|---|---|
DataSet |
data
The data behind this layer.
|
private static java.util.concurrent.atomic.AtomicInteger |
dataLayerCounter
the global counter for created data layers
|
private DataSetListenerAdapter |
dataSetListenerAdapter |
static int |
DEFAULT_RECENT_RELATIONS_NUMBER
The default number of relations in the recent relations cache.
|
private static java.awt.image.BufferedImage |
hatched
a texture for non-downloaded area
|
private static int |
HATCHED_SIZE |
private java.util.concurrent.atomic.AtomicBoolean |
isUploadInProgress
Flag used to know if the layer is being uploaded
|
private java.util.concurrent.CopyOnWriteArrayList<OsmDataLayer.LayerStateChangeListener> |
layerStateChangeListeners |
private static NamedColorProperty |
PROPERTY_BACKGROUND_COLOR |
static BooleanProperty |
PROPERTY_HIDE_LABELS_WHILE_DRAGGING
Property to determine if labels must be hidden while dragging the map.
|
private static NamedColorProperty |
PROPERTY_OUTSIDE_COLOR |
static IntegerProperty |
PROPERTY_RECENT_RELATIONS_NUMBER
The number of relations to use in the recent relations cache.
|
static StringProperty |
PROPERTY_SAVE_EXTENSION
The extension that should be used when saving the OSM file.
|
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.
|
private static boolean |
containsOnlyGpxTags(Tagged t) |
boolean |
containsPoint(LatLon coor)
Determines if this layer contains data at the given coordinate.
|
private static java.lang.String |
counterText(java.lang.String text,
int deleted,
int incomplete) |
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
|
(package private) static java.lang.String |
createLayerName(java.lang.Object arg) |
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.
|
DataSet |
getDataSet()
Returns the
DataSet behind this layer. |
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.
|
javax.swing.Action[] |
getMenuEntries()
Returns list of actions.
|
static java.awt.Color |
getOutsideColor()
Replies background color for non-downloaded areas.
|
java.util.List<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. |
static java.lang.String |
gpxVal(OsmPrimitive prim,
java.lang.String key)
Reads the Gpx key from the given
OsmPrimitive, with or without "gpx:" prefix |
void |
highlightUpdated(HighlightUpdateListener.HighlightUpdateEvent e)
Called whenever the highlighting of way segments in the dataset changed.
|
private boolean |
isDataSetEmpty()
Check the data set if it would be empty on save.
|
boolean |
isDownloadable()
Determines if the layer is able to download data and implements the
DownloadFromServer interface. |
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.
|
boolean |
isUploadInProgress()
Determines if upload of data managed by this layer is currently in progress.
|
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) |
static WayPoint |
nodeToWayPoint(Node n) |
static WayPoint |
nodeToWayPoint(Node n,
long time) |
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)
Called when notified about any type of dataset change event.
|
void |
projectionChanged(Projection oldValue,
Projection newValue) |
protected static void |
removeClipboardDataFor(OsmDataLayer osm) |
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(DataSelectionListener.SelectionChangeEvent event)
Called whenever the selection is changed.
|
void |
setName(java.lang.String name)
Sets the name of the layer
|
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.
|
void |
setUploadInProgress()
Sets the "upload in progress" flag, which will result in displaying a new icon and forbid to remove the layer.
|
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 |
unsetUploadInProgress()
Unsets the "upload in progress" flag, which will result in displaying the standard icon and allow to remove the layer.
|
void |
visitBoundingBox(BoundingXYVisitor v)
Visits the content bounds of this layer.
|
private static void |
waysToGpxData(java.util.Collection<Way> ways,
GpxData gpxData,
java.util.Set<Node> doneNodes) |
clear, isLocked, lock, unlockaddPropertyChangeListener, fireFilterStateChanged, fireOpacityChanged, fireVisibleChanged, getAssociatedFile, getChangesetSourceTag, getColor, getDefaultLayerPosition, getName, getOpacity, hasColor, hookUpMapView, isBackgroundLayer, isInfoResizable, isProjectionSupported, isRenamed, isVisible, nameSupportedProjections, removePropertyChangeListener, rename, setAssociatedFile, setBackgroundLayer, setColor, setFilterStateChanged, setOpacity, setVisible, toggleVisible, toStringaddInvalidationListener, attachToMapView, createMapViewPainter, invalidate, removeInvalidationListenerprivate static final int HATCHED_SIZE
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 final java.util.concurrent.atomic.AtomicBoolean isUploadInProgress
public final java.util.List<TestError> validationErrors
public static final int DEFAULT_RECENT_RELATIONS_NUMBER
getRecentRelations(),
Constant Field Valuespublic static final IntegerProperty PROPERTY_RECENT_RELATIONS_NUMBER
getRecentRelations()public static final StringProperty PROPERTY_SAVE_EXTENSION
public static final BooleanProperty PROPERTY_HIDE_LABELS_WHILE_DRAGGING
private static final NamedColorProperty PROPERTY_BACKGROUND_COLOR
private static final NamedColorProperty PROPERTY_OUTSIDE_COLOR
private final java.util.Map<Relation,java.lang.Void> recentRelations
private static final java.util.concurrent.atomic.AtomicInteger dataLayerCounter
private final java.util.concurrent.CopyOnWriteArrayList<OsmDataLayer.LayerStateChangeListener> layerStateChangeListeners
private DataSetListenerAdapter dataSetListenerAdapter
private static volatile java.awt.image.BufferedImage 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.List<Relation> getRecentRelations()
null if nonepublic void setRecentRelation(Relation relation)
relation - new entry for the list of recently closed relationsPROPERTY_RECENT_RELATIONS_NUMBERpublic void removeRecentRelation(Relation relation)
relation - relation to removeprotected void setRequiresSaveToFile(boolean newValue)
protected void setRequiresUploadToServer(boolean newValue)
public static java.lang.String createNewName()
static java.lang.String createLayerName(java.lang.Object arg)
public void addLayerStateChangeListener(OsmDataLayer.LayerStateChangeListener listener)
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()
public DataSet getDataSet()
DataSet behind this layer.getDataSet in class AbstractOsmDataLayerDataSet behind this layer.protected ImageProvider getBaseIconProvider()
public javax.swing.Icon getIcon()
Layerpublic void paint(java.awt.Graphics2D g, MapView mv, Bounds box)
paint in interface MapViewPaintableg - Graphicsmv - The object that can translate GeoPoints to screen coordinates.box - Bounding boxpublic java.lang.String getToolTipText()
getToolTipText in class Layerpublic void mergeFrom(Layer from)
Layerpublic 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 nullpublic boolean isMergable(Layer other)
isMergable in class Layerother - The other layer that is tested to be mergable with this.public void visitBoundingBox(BoundingXYVisitor v)
LayervisitBoundingBox in class Layerv - The visitor that gets notified about the contents of this 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 uploadedprivate static java.lang.String counterText(java.lang.String text, int deleted, int incomplete)
public java.lang.Object getInfoComponent()
LayergetInfoComponent in class LayerComponent describing the layer.public javax.swing.Action[] getMenuEntries()
LayerLayer.SeparatorLayerAction.INSTANCE instead of new JSeparatorgetMenuEntries in class Layerpublic 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 boolean containsOnlyGpxTags(Tagged t)
public static java.lang.String gpxVal(OsmPrimitive prim, java.lang.String key)
OsmPrimitive, with or without "gpx:" prefixprim - OSM primitivekey - GPX key without prefixnull if not presentpublic static WayPoint nodeToWayPoint(Node n)
n - the Node to convertWayPoint objectpublic static WayPoint nodeToWayPoint(Node n, long time)
n - the Node to converttime - a timestamp value in milliseconds from the epoch.WayPoint objectprivate 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 coorpublic ConflictCollection getConflicts()
public boolean isDownloadable()
DownloadFromServerDownloadFromServer interface. A layer that implements the
DownloadFromServer interface must return true.isDownloadable in interface DownloadFromServerisDownloadable in class AbstractModifiableLayertrue if the layer is able to download data; false, otherwisepublic boolean isUploadable()
UploadToServerUploadToServer interface. A layer that implements the
UploadToServer interface must return true.isUploadable in interface UploadToServerisUploadable in class AbstractModifiableLayertrue if the layer is able to upload data; false, otherwisepublic boolean requiresUploadToServer()
UploadToServerrequiresUploadToServer in interface UploadToServerrequiresUploadToServer in class AbstractModifiableLayertrue if the data managed by this layer needs to be
uploaded to the server because it contains modified data;
false, otherwisepublic boolean requiresSaveToFile()
SaveToFilerequiresSaveToFile in interface SaveToFilerequiresSaveToFile in class AbstractModifiableLayertrue if the data managed by this layer needs to be saved to a file; false, otherwisepublic void onPostLoadFromFile()
LayeronPostLoadFromFile in class Layerpublic void onPostDownloadFromServer()
public void onPostSaveToFile()
SaveToFileonPostSaveToFile in interface SaveToFileonPostSaveToFile in class AbstractModifiableLayerpublic void onPostUploadToServer()
AbstractModifiableLayeronPostUploadToServer in interface UploadToServeronPostUploadToServer in class AbstractModifiableLayerpublic void destroy()
Layerdestroy in interface Destroyabledestroy in class Layerprotected static void removeClipboardDataFor(OsmDataLayer osm)
public void processDatasetEvent(AbstractDatasetChangedEvent event)
DataSetListenerAdapter.ListenerprocessDatasetEvent in interface DataSetListenerAdapter.Listenerevent - dataset change eventpublic void selectionChanged(DataSelectionListener.SelectionChangeEvent event)
DataSelectionListenerselectionChanged in interface DataSelectionListenerevent - The selection change event.DataSelectionListener.SelectionChangeEventpublic void projectionChanged(Projection oldValue, Projection newValue)
projectionChanged in interface ProjectionChangeListenerprojectionChanged in class Layerpublic final boolean isUploadDiscouraged()
UploadToServerisUploadDiscouraged in interface UploadToServerisUploadDiscouraged in class AbstractModifiableLayertrue if upload is discouraged for this layer; false, otherwisepublic 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()
AbstractModifiableLayerisModified in class AbstractModifiableLayerpublic boolean isSavable()
LayerisSavable in interface SaveToFileisSavable in class Layerpublic boolean checkSaveConditions()
LayercheckSaveConditions in class Layertrue, if it is safe to save.private boolean isDataSetEmpty()
true, if a save result in an empty data set.public java.io.File createAndOpenSaveFileChooser()
LayercreateAndOpenSaveFileChooser in class LayerFileSaveActionBase.createAndOpenSaveFileChooser(java.lang.String, org.openstreetmap.josm.actions.ExtensionFileFilter)public AbstractIOTask createUploadTask(ProgressMonitor monitor)
UploadToServerAbstractIOTask for uploading data.createUploadTask in interface UploadToServercreateUploadTask in class AbstractModifiableLayermonitor - The progress monitorAbstractIOTask for uploading data, or null if not applicablepublic AbstractUploadDialog getUploadDialog()
UploadToServergetUploadDialog in interface UploadToServergetUploadDialog in class AbstractModifiableLayernull if not applicablepublic ProjectionBounds getViewProjectionBounds()
LayerProjectionBounds 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 Layerpublic void highlightUpdated(HighlightUpdateListener.HighlightUpdateEvent e)
HighlightUpdateListenerhighlightUpdated in interface HighlightUpdateListenere - The dataset highlight event.public void setName(java.lang.String name)
Layerpublic void setUploadInProgress()
public void unsetUploadInProgress()
public boolean isUploadInProgress()
UploadToServerisUploadInProgress in interface UploadToServerisUploadInProgress in class AbstractModifiableLayertrue if upload is in progress