org.openstreetmap.josm.gui.layer
Class Layer

java.lang.Object
  extended by org.openstreetmap.josm.gui.layer.Layer
All Implemented Interfaces:
ProjectionChangeListener, MapViewPaintable, Destroyable
Direct Known Subclasses:
GeoImageLayer, GpxLayer, ImageryLayer, MarkerLayer, OsmDataLayer, ValidatorLayer

public abstract class Layer
extends java.lang.Object
implements Destroyable, MapViewPaintable, 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
static interface Layer.LayerAction
           
static class Layer.LayerGpxExportAction
           
static class Layer.LayerSaveAction
          The action to save a layer
static class Layer.LayerSaveAsAction
           
static interface Layer.MultiLayerAction
           
static class Layer.SeparatorLayerAction
          Special class that can be returned by getMenuEntries when JSeparator needs to be created
 
Field Summary
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 handling
static int ICON_SIZE
           
private  java.lang.String name
          The name of this layer.
static java.lang.String NAME_PROP
           
private  double opacity
          The opacity of the layer.
static java.lang.String OPACITY_PROP
           
protected  java.beans.PropertyChangeSupport propertyChangeSupport
          keeps track of property change listeners
private  boolean visible
          The visibility state of the layer.
static java.lang.String VISIBLE_PROP
           
 
Constructor Summary
Layer(java.lang.String name)
          Create the layer and fill in the necessary components.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener
 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.
When the user has chosen a file, checks the file extension, and confirms overwrite if needed.
 void destroy()
          Called, when the layer is removed from the mapview and is going to be destroyed.
protected  void fireOpacityChanged(double oldValue, double newValue)
          fires a property change for the property OPACITY_PROP
protected  void fireVisibleChanged(boolean oldValue, boolean newValue)
          fires a property change for the property VISIBLE_PROP
 java.io.File getAssociatedFile()
           
 java.awt.Color getColor(boolean ignoreCustom)
          Return a Color for this layer.
abstract  javax.swing.Icon getIcon()
          Return a representative small image for this layer.
abstract  java.lang.Object getInfoComponent()
           
abstract  javax.swing.Action[] getMenuEntries()
          Returns list of actions.
 java.lang.String getName()
          Replies the name of the layer
 double getOpacity()
           
abstract  java.lang.String getToolTipText()
           
 void hookUpMapView()
          Initialization code, that depends on Main.map.mapView.
 boolean isBackgroundLayer()
          Replies true if this layer is a background layer
 boolean isChanged()
          Check changed status of layer
abstract  boolean isMergable(Layer other)
           
 boolean isProjectionSupported(Projection proj)
          allows to check whether a projection is supported or not
 boolean 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 projections
 void onPostLoadFromFile()
          Initializes the layer after a successful load of data from a file
abstract  void paint(java.awt.Graphics2D g, MapView mv, Bounds box)
          Paint the dataset using the engine set.
 void projectionChanged(Projection oldValue, Projection newValue)
           
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener
 void setAssociatedFile(java.io.File file)
           
 void setBackgroundLayer(boolean background)
          Sets whether this layer is a background layer
 void setName(java.lang.String name)
          Sets the name of the layer
 void setOpacity(double opacity)
           
 void setVisible(boolean visible)
          Sets the visibility of this layer.
 void toggleVisible()
          Toggles the visibility state of this layer.
abstract  void visitBoundingBox(BoundingXYVisitor v)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VISIBLE_PROP

public static final java.lang.String VISIBLE_PROP

OPACITY_PROP

public static final java.lang.String OPACITY_PROP

NAME_PROP

public static final java.lang.String NAME_PROP

ICON_SIZE

public static final int ICON_SIZE
See Also:
Constant Field Values

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.


associatedFile

private java.io.File associatedFile
If a file is associated with this layer, this variable should be set to it.

Constructor Detail

Layer

public Layer(java.lang.String name)
Create the layer and fill in the necessary components.

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. Instead override this method.


paint

public abstract void paint(java.awt.Graphics2D g,
                           MapView mv,
                           Bounds box)
Paint the dataset using the engine set.

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

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.


getColor

public java.awt.Color getColor(boolean ignoreCustom)
Return a Color for this layer. Return null when no color specified.

Parameters:
ignoreCustom - Custom color should return null, as no default color is used. When this is true, then even for custom coloring the base color is returned - mainly for layer internal use.

getToolTipText

public abstract java.lang.String getToolTipText()
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)
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)

getInfoComponent

public abstract java.lang.Object getInfoComponent()

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


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

getAssociatedFile

public java.io.File getAssociatedFile()

setAssociatedFile

public void setAssociatedFile(java.io.File file)

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.

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 property VISIBLE_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()

setOpacity

public void setOpacity(double opacity)

toggleVisible

public void toggleVisible()
Toggles the visibility state of this layer.


addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener

Parameters:
listener - the listener

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener

Parameters:
listener - the listener

fireVisibleChanged

protected void fireVisibleChanged(boolean oldValue,
                                  boolean newValue)
fires a property change for the property VISIBLE_PROP

Parameters:
oldValue - the old value
newValue - the new value

fireOpacityChanged

protected void fireOpacityChanged(double oldValue,
                                  double newValue)
fires a property change for the property OPACITY_PROP

Parameters:
oldValue - the old value
newValue - the new value

isChanged

public boolean isChanged()
Check changed status of layer

Returns:
True if layer was changed since last paint

isProjectionSupported

public boolean isProjectionSupported(Projection proj)
allows to check whether a projection is supported or not

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 interface ProjectionChangeListener

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

Returns:
The output File
Since:
5459
See Also:
SaveActionBase.createAndOpenSaveFileChooser(java.lang.String, org.openstreetmap.josm.actions.ExtensionFileFilter)


JOSM