Class MapRendererFactory
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.visitor.paint.MapRendererFactory
-
public final class MapRendererFactory extends java.lang.Object
MapRendererFactory manages a list of map renderer classes and associated meta data (display name, description).
Plugins can implement and supply their own map renderers.
Sample code in a pluginpublic class MyMapRenderer extends AbstractMapRenderer { // .... } // to be called when the plugin is created MapRendererFactory factory = MapRendererFactory.getInstance(); factory.register(MyMapRenderer.class, "My map renderer", "This is is a fast map renderer"); factory.activate(MyMapRenderer.class);
- Since:
- 4087
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MapRendererFactory.Descriptor
A description of a possible renderer for the mapstatic class
MapRendererFactory.MapRendererFactoryException
An exception thrown while creating a map renderer
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Class<? extends AbstractMapRenderer>
activeRenderer
private java.util.List<MapRendererFactory.Descriptor>
descriptors
private static MapRendererFactory
instance
static java.lang.String
PREF_KEY_RENDERER_CLASS_NAME
preference key for the renderer class name.
-
Constructor Summary
Constructors Modifier Constructor Description private
MapRendererFactory()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activate(java.lang.Class<? extends AbstractMapRenderer> renderer)
Activates a map renderer class.void
activateDefault()
Activates the default map renderer.private void
activateMapRenderer(java.lang.String rendererClassName)
AbstractMapRenderer
createActiveRenderer(java.awt.Graphics2D g, NavigatableComponent viewport, boolean isInactiveMode)
Creates an instance of the currently active renderer.static MapRendererFactory
getInstance()
Replies the unique instancejava.util.List<MapRendererFactory.Descriptor>
getMapRendererDescriptors()
Replies the (unmodifiable) list of map renderer descriptors.boolean
isMapRendererActive(java.lang.Class<? extends AbstractMapRenderer> clazz)
Replies true, if currently the specified map renderer is active.boolean
isRegistered(java.lang.Class<? extends AbstractMapRenderer> renderer)
Replies true, ifRenderer
is already a registered map renderer class.boolean
isWireframeMapRendererActive()
Replies true, if currently the wireframe map renderer is active.private static java.lang.Class<?>
loadRendererClass(java.lang.String className)
void
register(java.lang.Class<? extends AbstractMapRenderer> renderer, java.lang.String displayName, java.lang.String description)
Registers a map renderer class.private void
registerDefaultRenderers()
void
unregister(java.lang.Class<? extends AbstractMapRenderer> renderer)
Unregisters a map renderer class.
-
-
-
Field Detail
-
PREF_KEY_RENDERER_CLASS_NAME
public static final java.lang.String PREF_KEY_RENDERER_CLASS_NAME
preference key for the renderer class name. Default: class name forStyledMapRenderer
- See Also:
- Constant Field Values
-
instance
private static MapRendererFactory instance
-
descriptors
private final java.util.List<MapRendererFactory.Descriptor> descriptors
-
activeRenderer
private java.lang.Class<? extends AbstractMapRenderer> activeRenderer
-
-
Constructor Detail
-
MapRendererFactory
private MapRendererFactory()
-
-
Method Detail
-
getInstance
public static MapRendererFactory getInstance()
Replies the unique instance- Returns:
- instance of map rending class
-
loadRendererClass
private static java.lang.Class<?> loadRendererClass(java.lang.String className)
-
activateMapRenderer
private void activateMapRenderer(java.lang.String rendererClassName)
-
registerDefaultRenderers
private void registerDefaultRenderers()
-
isRegistered
public boolean isRegistered(java.lang.Class<? extends AbstractMapRenderer> renderer)
Replies true, if
Renderer
is already a registered map renderer class.- Parameters:
renderer
- the map renderer class. Must not be null.- Returns:
- true, if
Renderer
is already a registered map renderer class - Throws:
java.lang.IllegalArgumentException
- ifrenderer
is null
-
register
public void register(java.lang.Class<? extends AbstractMapRenderer> renderer, java.lang.String displayName, java.lang.String description)
Registers a map renderer class.
- Parameters:
renderer
- the map renderer class. Must not be null.displayName
- the display name to be displayed in UIs (i.e. in the preference dialog)description
- the description- Throws:
java.lang.IllegalArgumentException
- ifrenderer
is nulljava.lang.IllegalStateException
- ifrenderer
is already registered
-
unregister
public void unregister(java.lang.Class<? extends AbstractMapRenderer> renderer)
Unregisters a map renderer class.
If the respective class is also the active renderer, the renderer is reset to the default renderer.
- Parameters:
renderer
- the map renderer class. Must not be null.
-
activate
public void activate(java.lang.Class<? extends AbstractMapRenderer> renderer)
Activates a map renderer class.
The renderer class must already be registered.
- Parameters:
renderer
- the map renderer class. Must not be null.- Throws:
java.lang.IllegalArgumentException
- ifrenderer
is nulljava.lang.IllegalStateException
- ifrenderer
isn't registered yet
-
activateDefault
public void activateDefault()
Activates the default map renderer.
- Throws:
java.lang.IllegalStateException
- if the default rendererStyledMapRenderer
isn't registered
-
createActiveRenderer
public AbstractMapRenderer createActiveRenderer(java.awt.Graphics2D g, NavigatableComponent viewport, boolean isInactiveMode)
Creates an instance of the currently active renderer.
- Parameters:
g
- Graphicsviewport
- Navigable componentisInactiveMode
-true
if the paint visitor shall render OSM objects such that they look inactive- Returns:
- an instance of the currently active renderer
- Throws:
MapRendererFactory.MapRendererFactoryException
- if creating an instance fails- See Also:
AbstractMapRenderer(Graphics2D, NavigatableComponent, boolean)
-
getMapRendererDescriptors
public java.util.List<MapRendererFactory.Descriptor> getMapRendererDescriptors()
Replies the (unmodifiable) list of map renderer descriptors.
- Returns:
- the descriptors
-
isWireframeMapRendererActive
public boolean isWireframeMapRendererActive()
Replies true, if currently the wireframe map renderer is active. Otherwise, false.
There is a specific method for
WireframeMapRenderer
for legacy support. Until 03/2011 there were only two possible map renderers in JOSM: the wireframe renderer and the styled renderer. For the time being there are still UI elements (menu entries, etc.) which toggle between these two renderers only.- Returns:
- true, if currently the wireframe map renderer is active. Otherwise, false
-
isMapRendererActive
public boolean isMapRendererActive(java.lang.Class<? extends AbstractMapRenderer> clazz)
Replies true, if currently the specified map renderer is active. Otherwise, false.
- Parameters:
clazz
- The class that we are checking to see if it is the current renderer- Returns:
- true, if currently the wireframe map renderer is active. Otherwise, false
- Since:
- 19176
-
-