public abstract class Layer extends Object implements Destroyable, MapViewPaintable, ProjectionChangeListener
Modifier and Type | Class and Description |
---|---|
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
|
Modifier and Type | Field and Description |
---|---|
private 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 String |
FILTER_STATE_PROP |
static int |
ICON_SIZE |
private String |
name
The name of this layer.
|
static String |
NAME_PROP |
private double |
opacity
The opacity of the layer.
|
static String |
OPACITY_PROP |
protected PropertyChangeSupport |
propertyChangeSupport
keeps track of property change listeners
|
private boolean |
visible
The visibility state of the layer.
|
static String |
VISIBLE_PROP |
Constructor and Description |
---|
Layer(String name)
Create the layer and fill in the necessary components.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(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.)
|
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 long |
estimateMemoryUsage() |
protected void |
fireFilterStateChanged()
fires a property change for the property
FILTER_STATE_PROP . |
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 |
File |
getAssociatedFile() |
Color |
getColor(boolean ignoreCustom)
Return a Color for this layer.
|
abstract Icon |
getIcon()
Return a representative small image for this layer.
|
abstract Object |
getInfoComponent() |
abstract Action[] |
getMenuEntries()
Returns list of actions.
|
String |
getName()
Replies the name of the layer
|
double |
getOpacity() |
abstract 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
|
boolean |
isInfoResizable()
Determines if info dialog can be resized (false by default).
|
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.
|
String |
nameSupportedProjections()
Specify user information about projections
|
void |
onPostLoadFromFile()
Initializes the layer after a successful load of data from a file
|
abstract void |
paint(Graphics2D g,
MapView mv,
Bounds box)
Paint the dataset using the engine set.
|
void |
projectionChanged(Projection oldValue,
Projection newValue) |
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a
PropertyChangeListener |
void |
setAssociatedFile(File file) |
void |
setBackgroundLayer(boolean background)
Sets whether this layer is a background layer
|
void |
setFilterStateChanged()
Sets new state to the layer after applying
ImageProcessor . |
void |
setName(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) |
public static final String VISIBLE_PROP
public static final String OPACITY_PROP
public static final String FILTER_STATE_PROP
public static final int ICON_SIZE
protected PropertyChangeSupport propertyChangeSupport
private boolean visible
private double opacity
private boolean background
private File associatedFile
public void hookUpMapView()
estimateMemoryUsage
method and give a hint.
This allows for preemptive warning message for user, instead of failing later on
Remember to call super.hookUpMapView()
when overriding this methodpublic abstract void paint(Graphics2D g, MapView mv, Bounds box)
paint
in interface MapViewPaintable
mv
- The object that can translate GeoPoints to screen coordinates.g
- Graphicsbox
- Bounding boxpublic abstract Icon getIcon()
public Color getColor(boolean ignoreCustom)
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.public abstract String getToolTipText()
public abstract void mergeFrom(Layer from)
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.public abstract boolean isMergable(Layer other)
other
- The other layer that is tested to be mergable with this.public abstract void visitBoundingBox(BoundingXYVisitor v)
public abstract Object getInfoComponent()
public boolean isInfoResizable()
true
if the info dialog can be resized, false
otherwisepublic abstract Action[] getMenuEntries()
Layer.SeparatorLayerAction.INSTANCE
instead of new JSeparatorpublic void destroy()
destroy
in interface Destroyable
public File getAssociatedFile()
public void setAssociatedFile(File file)
public final void setName(String name)
name
- the name. If null, the name is set to the empty string.public boolean isBackgroundLayer()
public void setBackgroundLayer(boolean background)
background
- true, if this layer is a background layerpublic void setVisible(boolean visible)
VISIBLE_PROP
.visible
- true, if the layer is visible; false, otherwise.public boolean isVisible()
public double getOpacity()
public void setOpacity(double opacity)
public void setFilterStateChanged()
ImageProcessor
.public void toggleVisible()
public void addPropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
listener
- the listenerpublic void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
listener
- the listenerprotected void fireVisibleChanged(boolean oldValue, boolean newValue)
VISIBLE_PROP
oldValue
- the old valuenewValue
- the new valueprotected void fireOpacityChanged(double oldValue, double newValue)
OPACITY_PROP
oldValue
- the old valuenewValue
- the new valueprotected void fireFilterStateChanged()
FILTER_STATE_PROP
.public boolean isChanged()
public boolean isProjectionSupported(Projection proj)
proj
- projectionpublic String nameSupportedProjections()
public void projectionChanged(Projection oldValue, Projection newValue)
projectionChanged
in interface ProjectionChangeListener
public void onPostLoadFromFile()
public boolean isSavable()
public boolean checkSaveConditions()
true
, if it is safe to save.public File createAndOpenSaveFileChooser()
File
SaveActionBase.createAndOpenSaveFileChooser(java.lang.String, org.openstreetmap.josm.actions.ExtensionFileFilter)
protected long estimateMemoryUsage()