Class Layer
- java.lang.Object
-
- org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable
-
- org.openstreetmap.josm.gui.layer.Layer
-
- All Implemented Interfaces:
ProjectionChangeListener
,MapViewPaintable
,Destroyable
- Direct Known Subclasses:
AbstractModifiableLayer
,ImageryLayer
,MarkerLayer
,ValidatorLayer
public abstract class Layer extends AbstractMapViewPaintable implements Destroyable, ProjectionChangeListener
A layer encapsulates the gui component of one dataset and its representation.Some layers may display data directly imported from OSM server. Other only display background images. Some can be edited, some not. Some are static and other changes dynamically (auto-updated).
Layers can be visible or not. Most actions the user can do applies only on selected layers. The available actions depend on the selected layers too.
All layers are managed by the MapView. They are displayed in a list to the right of the screen.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Layer.LayerAction
Action related to a single layer.static class
Layer.LayerGpxExportAction
Action that exports the layer as gpx filestatic class
Layer.LayerSaveAction
The action to save a layerstatic class
Layer.LayerSaveAsAction
Action to save the layer in a new filestatic interface
Layer.MultiLayerAction
Action related to several layers.static class
Layer.SeparatorLayerAction
Special class that can be returned by getMenuEntries when JSeparator needs to be created-
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 java.io.File
associatedFile
If a file is associated with this layer, this variable should be set to it.private boolean
background
The layer should be handled as a background layer in automatic handlingstatic java.lang.String
FILTER_STATE_PROP
Property that defines the filter state.private boolean
isDestroyed
private java.lang.String
name
The name of this layer.static java.lang.String
NAME_PROP
The name property of the layer.private double
opacity
The opacity of the layer.static java.lang.String
OPACITY_PROP
The opacity of this layer.protected java.beans.PropertyChangeSupport
propertyChangeSupport
keeps track of property change listenersprivate boolean
renamed
This is set if user renamed this layer.private boolean
visible
The visibility state of the layer.static java.lang.String
VISIBLE_PROP
The visibility property for this layer.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Layer(java.lang.String name)
Create the layer and fill in the necessary components.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds aPropertyChangeListener
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.void
destroy()
Called, when the layer is removed from the mapview and is going to be destroyed.protected void
fireFilterStateChanged()
Fires a property change for the propertyFILTER_STATE_PROP
.protected void
fireOpacityChanged(double oldValue, double newValue)
fires a property change for the propertyOPACITY_PROP
protected void
fireVisibleChanged(boolean oldValue, boolean newValue)
fires a property change for the propertyVISIBLE_PROP
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 layerLayerPositionStrategy
getDefaultLayerPosition()
Gets the strategy that specifies where this layer should be inserted in a layer list.abstract javax.swing.Icon
getIcon()
Return a representative small image for this layer.abstract 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.abstract javax.swing.Action[]
getMenuEntries()
Returns list of actions.java.lang.String
getName()
Replies the name of the layerdouble
getOpacity()
Gets the opacity of the layer, in range 0...1abstract java.lang.String
getToolTipText()
Returns a small tooltip hint about some statistics for this layer.ProjectionBounds
getViewProjectionBounds()
Gets theProjectionBounds
for this layer to be visible to the user.boolean
hasColor()
Determines whether the layer has / can handle colors.void
hookUpMapView()
Initialization code, that depends on Main.map.mapView.boolean
isBackgroundLayer()
Replies true if this layer is a background layerboolean
isInfoResizable()
Determines if info dialog can be resized (false by default).abstract boolean
isMergable(Layer other)
Determines if the other layer can be merged into this layer.boolean
isProjectionSupported(Projection proj)
Allows to check whether a projection is supported or not.boolean
isRenamed()
Replies true if user renamed this layerboolean
isSavable()
Replies the savable state of this layer (i.e., if it can be saved through a "File → Save" dialog).boolean
isVisible()
Replies true if this layer is visible.abstract void
mergeFrom(Layer from)
Merges the given layer into this layer.java.lang.String
nameSupportedProjections()
Specify user information about projectionsvoid
onPostLoadFromFile()
Initializes the layer after a successful load of data from a filevoid
projectionChanged(Projection oldValue, Projection newValue)
void
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes aPropertyChangeListener
void
rename(java.lang.String name)
Rename layer and set renamed flag to mark it as renamed (has user given name).void
setAssociatedFile(java.io.File file)
Sets the associated file for this layer.void
setBackgroundLayer(boolean background)
Sets whether this layer is a background layervoid
setColor(java.awt.Color color)
Sets the color for this layer.void
setFilterStateChanged()
Sets new state to the layer after applyingImageProcessor
.void
setName(java.lang.String name)
Sets the name of the layervoid
setOpacity(double opacity)
Sets the opacity of the layer, in range 0...1void
setVisible(boolean visible)
Sets the visibility of this layer.void
toggleVisible()
Toggles the visibility state of this layer.java.lang.String
toString()
abstract void
visitBoundingBox(BoundingXYVisitor v)
Visits the content bounds of this layer.-
Methods inherited from class org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable
addInvalidationListener, attachToMapView, createMapViewPainter, invalidate, removeInvalidationListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.gui.layer.MapViewPaintable
paint
-
-
-
-
Field Detail
-
VISIBLE_PROP
public static final java.lang.String VISIBLE_PROP
The visibility property for this layer. May betrue
(visible) orfalse
(hidden).
-
OPACITY_PROP
public static final java.lang.String OPACITY_PROP
The opacity of this layer. A number between 0 and 1
-
NAME_PROP
public static final java.lang.String NAME_PROP
The name property of the layer. You can listen to name changes by listening to changes to this property.
-
FILTER_STATE_PROP
public static final java.lang.String FILTER_STATE_PROP
Property that defines the filter state. This is currently not used.
-
propertyChangeSupport
protected java.beans.PropertyChangeSupport propertyChangeSupport
keeps track of property change listeners
-
visible
private boolean visible
The visibility state of the layer.
-
opacity
private double opacity
The opacity of the layer.
-
background
private boolean background
The layer should be handled as a background layer in automatic handling
-
name
private java.lang.String name
The name of this layer.
-
renamed
private boolean renamed
This is set if user renamed this layer.
-
associatedFile
private java.io.File associatedFile
If a file is associated with this layer, this variable should be set to it.
-
isDestroyed
private boolean isDestroyed
-
-
Constructor Detail
-
Layer
protected Layer(java.lang.String name)
Create the layer and fill in the necessary components.- Parameters:
name
- Layer name
-
-
Method Detail
-
hookUpMapView
public void hookUpMapView()
Initialization code, that depends on Main.map.mapView.It is always called in the event dispatching thread. Note that Main.map is null as long as no layer has been added, so do not execute code in the constructor, that assumes Main.map.mapView is not null.
If you need to execute code when this layer is added to the map view, use
AbstractMapViewPaintable.attachToMapView(org.openstreetmap.josm.gui.layer.MapViewPaintable.MapViewEvent)
-
getIcon
public abstract javax.swing.Icon getIcon()
Return a representative small image for this layer. The image must not be larger than 64 pixel in any dimension.- Returns:
- layer icon
-
hasColor
public boolean hasColor()
Determines whether the layer has / can handle colors.- Returns:
- whether the layer has / can handle colors.
- Since:
- 15496
-
getColor
public java.awt.Color getColor()
Return the current color of the layer- Returns:
- null when not present or not supported
- Since:
- 15496
-
setColor
public void setColor(java.awt.Color color)
Sets the color for this layer. Nothing happens if not supported by the layer- Parameters:
color
- the color to be set,null
for default- Since:
- 15496
-
getToolTipText
public abstract java.lang.String getToolTipText()
Returns a small tooltip hint about some statistics for this layer.- Returns:
- A small tooltip hint about some statistics for this layer.
-
mergeFrom
public abstract void mergeFrom(Layer from)
Merges the given layer into this layer. Throws if the layer types are incompatible.- 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.
-
isMergable
public abstract boolean isMergable(Layer other)
Determines if the other layer can be merged into this 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 abstract void visitBoundingBox(BoundingXYVisitor v)
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.- Parameters:
v
- The visitor that gets notified about the contents of this layer.
-
getInfoComponent
public abstract java.lang.Object getInfoComponent()
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.- Returns:
- Either a String or a
Component
describing the layer.
-
isInfoResizable
public boolean isInfoResizable()
Determines if info dialog can be resized (false by default).- Returns:
true
if the info dialog can be resized,false
otherwise- Since:
- 6708
-
getMenuEntries
public abstract javax.swing.Action[] getMenuEntries()
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- Returns:
- menu actions for this layer
-
destroy
public void destroy()
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
-
getAssociatedFile
public java.io.File getAssociatedFile()
Gets the associated file for this layer.- Returns:
- The file or
null
if it is unset. - See Also:
setAssociatedFile(File)
-
setAssociatedFile
public void setAssociatedFile(java.io.File file)
Sets the associated file for this layer.The associated file might be the one that the user opened.
- Parameters:
file
- The file, may benull
-
getLabel
public java.lang.String getLabel()
Replies a label for this layer useful for UI elements. Defaults to the layer name- Returns:
- a label for this layer
- Since:
- 17626
-
getName
public java.lang.String getName()
Replies the name of the layer- Returns:
- the name of the layer
-
setName
public void setName(java.lang.String name)
Sets the name of the layer- Parameters:
name
- the name. If null, the name is set to the empty string.
-
rename
public final void rename(java.lang.String name)
Rename layer and set renamed flag to mark it as renamed (has user given name).- Parameters:
name
- the name. If null, the name is set to the empty string.
-
isRenamed
public boolean isRenamed()
Replies true if user renamed this layer- Returns:
- true if user renamed this layer
-
isBackgroundLayer
public boolean isBackgroundLayer()
Replies true if this layer is a background layer- Returns:
- true if this layer is a background layer
-
setBackgroundLayer
public void setBackgroundLayer(boolean background)
Sets whether this layer is a background layer- Parameters:
background
- true, if this layer is a background layer
-
setVisible
public void setVisible(boolean visible)
Sets the visibility of this layer. Emits property change event for propertyVISIBLE_PROP
.- Parameters:
visible
- true, if the layer is visible; false, otherwise.
-
isVisible
public boolean isVisible()
Replies true if this layer is visible. False, otherwise.- Returns:
- true if this layer is visible. False, otherwise.
-
getOpacity
public double getOpacity()
Gets the opacity of the layer, in range 0...1- Returns:
- The opacity
-
setOpacity
public void setOpacity(double opacity)
Sets the opacity of the layer, in range 0...1- Parameters:
opacity
- The opacity- Throws:
java.lang.IllegalArgumentException
- if the opacity is out of range
-
setFilterStateChanged
public void setFilterStateChanged()
Sets new state to the layer after applyingImageProcessor
.
-
toggleVisible
public void toggleVisible()
Toggles the visibility state of this layer.
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds aPropertyChangeListener
- Parameters:
listener
- the listener
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes aPropertyChangeListener
- Parameters:
listener
- the listener
-
fireVisibleChanged
protected void fireVisibleChanged(boolean oldValue, boolean newValue)
fires a property change for the propertyVISIBLE_PROP
- Parameters:
oldValue
- the old valuenewValue
- the new value
-
fireOpacityChanged
protected void fireOpacityChanged(double oldValue, double newValue)
fires a property change for the propertyOPACITY_PROP
- Parameters:
oldValue
- the old valuenewValue
- the new value
-
fireFilterStateChanged
protected void fireFilterStateChanged()
Fires a property change for the propertyFILTER_STATE_PROP
.
-
isProjectionSupported
public boolean isProjectionSupported(Projection proj)
Allows to check whether a projection is supported or not.- Parameters:
proj
- projection- Returns:
- True if projection is supported for this layer
-
nameSupportedProjections
public java.lang.String nameSupportedProjections()
Specify user information about projections- Returns:
- User readable text telling about supported projections
-
projectionChanged
public void projectionChanged(Projection oldValue, Projection newValue)
- Specified by:
projectionChanged
in interfaceProjectionChangeListener
-
onPostLoadFromFile
public void onPostLoadFromFile()
Initializes the layer after a successful load of data from a file- Since:
- 5459
-
isSavable
public boolean isSavable()
Replies the savable state of this layer (i.e., if it can be saved through a "File → Save" dialog).- Returns:
- true if this layer can be saved to a file
- Since:
- 5459
-
checkSaveConditions
public boolean checkSaveConditions()
Checks whether it is ok to launch a save (whether we have data, there is no conflict etc.)- Returns:
true
, if it is safe to save.- Since:
- 5459
-
createAndOpenSaveFileChooser
public 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 overwriting if needed.
- Returns:
- The output
File
- Since:
- 5459
- See Also:
SaveActionBase.createAndOpenSaveFileChooser(java.lang.String, org.openstreetmap.josm.actions.ExtensionFileFilter)
-
getDefaultLayerPosition
public LayerPositionStrategy getDefaultLayerPosition()
Gets the strategy that specifies where this layer should be inserted in a layer list.- Returns:
- That strategy.
- Since:
- 10008
-
getViewProjectionBounds
public ProjectionBounds getViewProjectionBounds()
Gets theProjectionBounds
for this layer to be visible to the user. This can be the exact bounds, the UI handles padding. Returnnull
if you cannot provide this information. The default implementation uses the bounds fromvisitBoundingBox(BoundingXYVisitor)
.- Returns:
- The bounds for this layer.
- Since:
- 10371
-
getChangesetSourceTag
public java.lang.String getChangesetSourceTag()
Get the source for the layer- Returns:
- The string for the changeset source tag or
null
- Since:
- 15371
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-