org.openstreetmap.josm.gui.layer
Class OsmDataLayer

java.lang.Object
  extended by org.openstreetmap.josm.gui.layer.Layer
      extended by org.openstreetmap.josm.gui.layer.OsmDataLayer
All Implemented Interfaces:
DataSetListenerAdapter.Listener, ProjectionChangeListener, SelectionChangedListener, MapViewPaintable, Destroyable

public class OsmDataLayer
extends Layer
implements DataSetListenerAdapter.Listener, SelectionChangedListener

A layer that holds OSM data from a specific dataset. The data can be fully edited.


Nested Class Summary
static interface OsmDataLayer.CommandQueueListener
           
private  class OsmDataLayer.ConsistencyTestAction
           
 class OsmDataLayer.ConvertToGpxLayerAction
           
static class OsmDataLayer.DataCountVisitor
           
 
Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.layer.Layer
Layer.LayerAction, Layer.LayerGpxExportAction, Layer.LayerSaveAction, Layer.LayerSaveAsAction, Layer.MultiLayerAction, Layer.SeparatorLayerAction
 
Field Summary
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
private static java.awt.TexturePaint hatched
          a paint texture for non-downloaded area
private  int highlightUpdateCount
           
private  boolean isChanged
           
static java.lang.String REQUIRES_SAVE_TO_DISK_PROP
           
static java.lang.String REQUIRES_UPLOAD_TO_SERVER_PROP
           
private  boolean requiresSaveToFile
           
private  boolean requiresUploadToServer
           
 java.util.List<TestError> validationErrors
           
 
Fields inherited from class org.openstreetmap.josm.gui.layer.Layer
ICON_SIZE, NAME_PROP, OPACITY_PROP, propertyChangeSupport, VISIBLE_PROP
 
Constructor Summary
OsmDataLayer(DataSet data, java.lang.String name, java.io.File associatedFile)
          Construct a OsmDataLayer.
 
Method Summary
 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<IPrimitive> processed)
          Clean out the data behind the layer.
 boolean containsPoint(LatLon coor)
           
 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
 void destroy()
          Called, when the layer is removed from the mapview and is going to be destroyed.
static java.awt.Color getBackgroundColor()
           
protected  javax.swing.Icon getBaseIcon()
           
 ConflictCollection getConflicts()
          replies the set of conflicts currently managed in this layer
 javax.swing.Icon getIcon()
          TODO: @return Return a dynamic drawn icon of the map data.
 java.lang.Object getInfoComponent()
           
 javax.swing.Action[] getMenuEntries()
          Returns list of actions.
static java.awt.Color getOutsideColor()
           
 java.lang.String getToolTipText()
           
 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 isSavable()
          Replies the savable state of this layer (i.e if it can be saved through a "File->Save" dialog).
 boolean isUploadDiscouraged()
           
 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.
 void onPostDownloadFromServer()
           
 void onPostLoadFromFile()
          Initializes the layer after a successful load of data from a file
 void onPostSaveToFile()
          Initializes the layer after a successful save of OSM 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)
           
 boolean requiresSaveToFile()
          Replies true if the data managed by this layer needs to be saved to a file.
 boolean requiresUploadToServer()
          Replies true if the data managed by this layer needs to be uploaded to the server because it contains at least one modified primitive.
 void selectionChanged(java.util.Collection<? extends OsmPrimitive> newSelection)
          Informs the listener that the selection in the dataset has changed.
protected  void setRequiresSaveToFile(boolean newValue)
           
protected  void setRequiresUploadToServer(boolean newValue)
           
 void setUploadDiscouraged(boolean uploadDiscouraged)
           
 GpxData toGpxData()
           
static GpxData toGpxData(DataSet data, java.io.File file)
           
 void visitBoundingBox(BoundingXYVisitor v)
           
protected  void warnNumNewConflicts(int numNewConflicts)
          Warns the user about the number of detected conflicts
 
Methods inherited from class org.openstreetmap.josm.gui.layer.Layer
addPropertyChangeListener, fireOpacityChanged, fireVisibleChanged, getAssociatedFile, getColor, getName, getOpacity, hookUpMapView, isBackgroundLayer, isProjectionSupported, isVisible, nameSupportedProjections, removePropertyChangeListener, setAssociatedFile, setBackgroundLayer, setName, setOpacity, setVisible, toggleVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REQUIRES_SAVE_TO_DISK_PROP

public static final java.lang.String REQUIRES_SAVE_TO_DISK_PROP

REQUIRES_UPLOAD_TO_SERVER_PROP

public static final java.lang.String REQUIRES_UPLOAD_TO_SERVER_PROP

requiresSaveToFile

private boolean requiresSaveToFile

requiresUploadToServer

private boolean requiresUploadToServer

isChanged

private boolean isChanged

highlightUpdateCount

private int highlightUpdateCount

validationErrors

public java.util.List<TestError> validationErrors

dataLayerCounter

private static int dataLayerCounter
the global counter for created data layers


data

public final DataSet data
The data behind this layer.


conflicts

private ConflictCollection conflicts
the collection of conflicts detected in this layer


hatched

private static java.awt.TexturePaint hatched
a paint texture for non-downloaded area

Constructor Detail

OsmDataLayer

public OsmDataLayer(DataSet data,
                    java.lang.String name,
                    java.io.File associatedFile)
Construct a OsmDataLayer.

Method Detail

setRequiresSaveToFile

protected void setRequiresSaveToFile(boolean newValue)

setRequiresUploadToServer

protected void setRequiresUploadToServer(boolean newValue)

createNewName

public static java.lang.String createNewName()
Replies a new unique name for a data layer

Returns:
a new unique name for a data layer

getBackgroundColor

public static java.awt.Color getBackgroundColor()

getOutsideColor

public static java.awt.Color getOutsideColor()

createHatchTexture

public static void createHatchTexture()
Initialize the hatch pattern used to paint the non-downloaded area


getBaseIcon

protected javax.swing.Icon getBaseIcon()

getIcon

public javax.swing.Icon getIcon()
TODO: @return Return a dynamic drawn icon of the map data. The icon is updated by a background thread to not disturb the running programm.

Specified by:
getIcon in class Layer

paint

public 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). Draw nodes last to overlap the ways they belong to.

Specified by:
paint in interface MapViewPaintable
Specified by:
paint in class Layer
mv - The object that can translate GeoPoints to screen coordinates.

getToolTipText

public java.lang.String getToolTipText()
Specified by:
getToolTipText in class Layer
Returns:
A small tooltip hint about some statistics for this layer.

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.

Specified by:
mergeFrom in class Layer
Parameters:
from - The layer that get merged into this one. After the merge, the other layer is not usable anymore and passing to one others mergeFrom should be one of the last things to do with a layer.

mergeFrom

public void mergeFrom(DataSet from)
merges the primitives in dataset from into the dataset of this layer

Parameters:
from - the source data set

mergeFrom

public void mergeFrom(DataSet from,
                      ProgressMonitor progressMonitor)
merges the primitives in dataset from into the dataset of this layer

Parameters:
from - the source data set

warnNumNewConflicts

protected void warnNumNewConflicts(int numNewConflicts)
Warns the user about the number of detected conflicts

Parameters:
numNewConflicts - the number of detected conflicts

isMergable

public boolean isMergable(Layer other)
Specified by:
isMergable in class Layer
Parameters:
other - The other layer that is tested to be mergable with this.
Returns:
Whether the other layer can be merged into this layer.

visitBoundingBox

public void visitBoundingBox(BoundingXYVisitor v)
Specified by:
visitBoundingBox in class Layer

cleanupAfterUpload

public void cleanupAfterUpload(java.util.Collection<IPrimitive> processed)
Clean out the data behind the layer. This means clearing the redo/undo lists, really deleting all deleted objects and reset the modified flags. This should be done after an upload, even after a partial upload.

Parameters:
processed - A list of all objects that were actually uploaded. May be null, which means nothing has been uploaded

getInfoComponent

public java.lang.Object getInfoComponent()
Specified by:
getInfoComponent in class Layer

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 SeparatorLayerAction.INSTANCE instead of new JSeparator

Specified by:
getMenuEntries in class Layer

toGpxData

public static GpxData toGpxData(DataSet data,
                                java.io.File file)

toGpxData

public GpxData toGpxData()

containsPoint

public boolean containsPoint(LatLon coor)

getConflicts

public ConflictCollection getConflicts()
replies the set of conflicts currently managed in this layer

Returns:
the set of conflicts currently managed in this layer

requiresUploadToServer

public boolean requiresUploadToServer()
Replies true if the data managed by this layer needs to be uploaded to the server because it contains at least one modified primitive.

Returns:
true if the data managed by this layer needs to be uploaded to the server because it contains at least one modified primitive; false, otherwise

requiresSaveToFile

public boolean requiresSaveToFile()
Replies true 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.

Returns:
true if the data managed by this layer needs to be saved to a file

onPostLoadFromFile

public void onPostLoadFromFile()
Description copied from class: Layer
Initializes the layer after a successful load of data from a file

Overrides:
onPostLoadFromFile in class Layer

onPostDownloadFromServer

public void onPostDownloadFromServer()

isChanged

public boolean isChanged()
Description copied from class: Layer
Check changed status of layer

Overrides:
isChanged in class Layer
Returns:
True if layer was changed since last paint

onPostSaveToFile

public void onPostSaveToFile()
Initializes the layer after a successful save of OSM data to a file


onPostUploadToServer

public void onPostUploadToServer()
Initializes the layer after a successful upload to the server


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 can not add itself safely as listener to the layerlist dialog, because there may be no such dialog yet (loaded via command line parameter).

Specified by:
destroy in interface Destroyable
Overrides:
destroy in class Layer

processDatasetEvent

public void processDatasetEvent(AbstractDatasetChangedEvent event)
Specified by:
processDatasetEvent in interface DataSetListenerAdapter.Listener

selectionChanged

public void selectionChanged(java.util.Collection<? extends OsmPrimitive> newSelection)
Description copied from interface: SelectionChangedListener
Informs the listener that the selection in the dataset has changed.

Specified by:
selectionChanged in interface SelectionChangedListener
Parameters:
newSelection - The new selection.

projectionChanged

public void projectionChanged(Projection oldValue,
                              Projection newValue)
Specified by:
projectionChanged in interface ProjectionChangeListener
Overrides:
projectionChanged in class Layer

isUploadDiscouraged

public final boolean isUploadDiscouraged()

setUploadDiscouraged

public final void setUploadDiscouraged(boolean uploadDiscouraged)

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).

Overrides:
isSavable in class Layer
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 class Layer
Returns:
true, if it is safe to save.

isDataSetEmpty

private boolean isDataSetEmpty()
Check the data set if it would be empty on save. It is empty, if it contains no objects (after all objects that are created and deleted without being transferred to the server have been removed).

Returns:
true, if a save result in an empty data set.

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 overwrite if needed.

Overrides:
createAndOpenSaveFileChooser in class Layer
Returns:
The output File
See Also:
SaveActionBase.createAndOpenSaveFileChooser(java.lang.String, org.openstreetmap.josm.actions.ExtensionFileFilter)


JOSM