org.openstreetmap.josm.gui.layer.markerlayer
Class Marker

java.lang.Object
  extended by org.openstreetmap.josm.gui.layer.markerlayer.Marker
All Implemented Interfaces:
TemplateEngineDataProvider
Direct Known Subclasses:
ButtonMarker, PlayHeadMarker

public class Marker
extends java.lang.Object
implements TemplateEngineDataProvider

Basic marker class. Requires a position, and supports a custom icon and a name. This class is also used to create appropriate Marker-type objects when waypoints are imported. It hosts a public list object, named makers, containing implementations of the MarkerMaker interface. Whenever a Marker needs to be created, each object in makers is called with the waypoint parameters (Lat/Lon and tag data), and the first one to return a Marker object wins. By default, one the list contains one default "Maker" implementation that will create AudioMarkers for .wav files, ImageMarkers for .png/.jpg/.jpeg files, and WebMarkers for everything else. (The creation of a WebMarker will fail if there's no valid URL in the tag, so it might still make sense to add Makers for such waypoints at the end of the list.) The default implementation only looks at the value of the tag inside the tag of the GPX file.

HowTo implement a new Marker


Nested Class Summary
static class Marker.TemplateEntryProperty
           
 
Field Summary
private  java.lang.String cachedText
           
private  CachedLatLon coor
           
private  TemplateEngineDataProvider dataProvider
           
static java.lang.String LABEL_PATTERN_AUTO
           
static java.lang.String LABEL_PATTERN_DESC
           
static java.lang.String LABEL_PATTERN_NAME
           
static java.lang.String MARKER_FORMATTED_OFFSET
           
static java.lang.String MARKER_OFFSET
           
static java.util.List<MarkerProducers> markerProducers
          Plugins can add their Marker creation stuff at the bottom or top of this list (depending on whether they want to override default behaviour or just add new stuff).
 double offset
           
 MarkerLayer parentLayer
           
 javax.swing.Icon symbol
           
private  java.lang.String text
           
private  int textVersion
           
 double time
           
 
Constructor Summary
Marker(LatLon ll, java.lang.String text, java.lang.String iconName, MarkerLayer parentLayer, double time, double offset)
           
Marker(LatLon ll, TemplateEngineDataProvider dataProvider, java.lang.String iconName, MarkerLayer parentLayer, double time, double offset)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ev)
          Called when the mouse is clicked in the marker's hotspot.
 boolean containsPoint(java.awt.Point p)
          Checks whether the marker display area contains the given point.
static Marker createMarker(WayPoint wpt, java.io.File relativePath, MarkerLayer parentLayer, double time, double offset)
          Returns an object of class Marker or one of its subclasses created from the parameters given.
 boolean evaluateCondition(SearchCompiler.Match condition)
           
private  java.lang.String formatOffset()
           
 LatLon getCoor()
           
 EastNorth getEastNorth()
           
 java.util.Collection<java.lang.String> getTemplateKeys()
           
 java.lang.Object getTemplateValue(java.lang.String name, boolean special)
           
 java.lang.String getText()
          Returns the Text which should be displayed, depending on chosen preference
protected  Marker.TemplateEntryProperty getTextTemplate()
           
 void paint(java.awt.Graphics g, MapView mv, boolean mousePressed, boolean showTextOrIcon)
          Paints the marker.
 void setCoor(LatLon coor)
           
 void setEastNorth(EastNorth eastNorth)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

markerProducers

public static final java.util.List<MarkerProducers> markerProducers
Plugins can add their Marker creation stuff at the bottom or top of this list (depending on whether they want to override default behaviour or just add new stuff).


MARKER_OFFSET

public static final java.lang.String MARKER_OFFSET
See Also:
Constant Field Values

MARKER_FORMATTED_OFFSET

public static final java.lang.String MARKER_FORMATTED_OFFSET
See Also:
Constant Field Values

LABEL_PATTERN_AUTO

public static final java.lang.String LABEL_PATTERN_AUTO
See Also:
Constant Field Values

LABEL_PATTERN_NAME

public static final java.lang.String LABEL_PATTERN_NAME
See Also:
Constant Field Values

LABEL_PATTERN_DESC

public static final java.lang.String LABEL_PATTERN_DESC
See Also:
Constant Field Values

dataProvider

private final TemplateEngineDataProvider dataProvider

text

private final java.lang.String text

symbol

public final javax.swing.Icon symbol

parentLayer

public final MarkerLayer parentLayer

time

public double time

offset

public double offset

cachedText

private java.lang.String cachedText

textVersion

private int textVersion

coor

private CachedLatLon coor
Constructor Detail

Marker

public Marker(LatLon ll,
              TemplateEngineDataProvider dataProvider,
              java.lang.String iconName,
              MarkerLayer parentLayer,
              double time,
              double offset)

Marker

public Marker(LatLon ll,
              java.lang.String text,
              java.lang.String iconName,
              MarkerLayer parentLayer,
              double time,
              double offset)
Method Detail

createMarker

public static Marker createMarker(WayPoint wpt,
                                  java.io.File relativePath,
                                  MarkerLayer parentLayer,
                                  double time,
                                  double offset)
Returns an object of class Marker or one of its subclasses created from the parameters given.

Parameters:
wpt - waypoint data for marker
relativePath - An path to use for constructing relative URLs or null for no relative URLs
offset - double in seconds as the time offset of this marker from the GPX file from which it was derived (if any).
Returns:
a new Marker object

setCoor

public final void setCoor(LatLon coor)

getCoor

public final LatLon getCoor()

setEastNorth

public final void setEastNorth(EastNorth eastNorth)

getEastNorth

public final EastNorth getEastNorth()

containsPoint

public boolean containsPoint(java.awt.Point p)
Checks whether the marker display area contains the given point. Markers not interested in mouse clicks may always return false.

Parameters:
p - The point to check
Returns:
true if the marker "hotspot" contains the point.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ev)
Called when the mouse is clicked in the marker's hotspot. Never called for markers which always return false from containsPoint.

Parameters:
ev - A dummy ActionEvent

paint

public void paint(java.awt.Graphics g,
                  MapView mv,
                  boolean mousePressed,
                  boolean showTextOrIcon)
Paints the marker.

Parameters:
g - graphics context
mv - map view
mousePressed - true if the left mouse button is pressed

getTextTemplate

protected Marker.TemplateEntryProperty getTextTemplate()

getText

public java.lang.String getText()
Returns the Text which should be displayed, depending on chosen preference

Returns:
Text of the label

getTemplateKeys

public java.util.Collection<java.lang.String> getTemplateKeys()
Specified by:
getTemplateKeys in interface TemplateEngineDataProvider

formatOffset

private java.lang.String formatOffset()

getTemplateValue

public java.lang.Object getTemplateValue(java.lang.String name,
                                         boolean special)
Specified by:
getTemplateValue in interface TemplateEngineDataProvider

evaluateCondition

public boolean evaluateCondition(SearchCompiler.Match condition)
Specified by:
evaluateCondition in interface TemplateEngineDataProvider


JOSM