org.openstreetmap.josm.gui
Class DefaultNameFormatter

java.lang.Object
  extended by org.openstreetmap.josm.gui.DefaultNameFormatter
All Implemented Interfaces:
HistoryNameFormatter, NameFormatter

public class DefaultNameFormatter
extends java.lang.Object
implements NameFormatter, HistoryNameFormatter

This is the default implementation of a NameFormatter for names of OsmPrimitives.


Field Summary
static java.lang.String[] DEFAULT_NAMING_TAGS_FOR_RELATIONS
          The default list of tags which are used as naming tags in relations.
private static java.util.LinkedList<NameFormatterHook> formatHooks
           
private static DefaultNameFormatter instance
           
private static java.util.List<java.lang.String> namingTagsForRelations
          the current list of tags used as naming tags in relations
private  java.util.Comparator<Node> nodeComparator
           
private  java.util.Comparator<Relation> relationComparator
           
private  java.util.Comparator<Way> wayComparator
           
 
Constructor Summary
DefaultNameFormatter()
           
 
Method Summary
 java.lang.String buildDefaultToolTip(HistoryOsmPrimitive primitive)
          Builds a default tooltip text for an HistoryOsmPrimitive primitive.
 java.lang.String buildDefaultToolTip(IPrimitive primitive)
          Builds a default tooltip text for the primitive primitive.
protected  void decorateNameWithId(java.lang.StringBuilder name, HistoryOsmPrimitive primitive)
          Decorates the name of primitive with its id, if the preference osm-primitives.showid is set.
protected  void decorateNameWithId(java.lang.StringBuilder name, IPrimitive primitive)
          Decorates the name of primitive with its id, if the preference osm-primitives.showid is set.
 java.lang.String format(Changeset changeset)
          Formats a name for a changeset
 java.lang.String format(HistoryNode node)
          Formats a name for a history node
 java.lang.String format(HistoryRelation relation)
          Formats a name for a HistoryRelation)
 java.lang.String format(HistoryWay way)
          Formats a name for a way
 java.lang.String format(Node node)
          Formats a name for a node
 java.lang.String format(Relation relation)
          Formats a name for a relation
 java.lang.String format(Way way)
          Formats a name for a way
 java.lang.String formatAsHtmlUnorderedList(java.util.Collection<? extends OsmPrimitive> primitives)
           
 java.lang.String formatAsHtmlUnorderedList(OsmPrimitive... primitives)
           
private  void formatRelationNameAndType(Relation relation, java.lang.StringBuilder result, TaggingPreset preset)
           
static DefaultNameFormatter getInstance()
          Replies the unique instance of this formatter
private  java.lang.String getLeadingNumber(java.lang.String s)
           
private  java.lang.String getNameTagValue(IRelation relation, java.lang.String nameTag)
           
static java.util.List<java.lang.String> getNamingtagsForRelations()
          Replies the list of naming tags used in relations.
 java.util.Comparator<Node> getNodeComparator()
           
 java.util.Comparator<Relation> getRelationComparator()
           
private  java.lang.String getRelationName(IRelation relation)
           
private  java.lang.String getRelationTypeName(IRelation relation)
           
 java.util.Comparator<Way> getWayComparator()
           
static void registerFormatHook(NameFormatterHook hook)
          Registers a format hook.
static void unregisterFormatHook(NameFormatterHook hook)
          Unregisters a format hook.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static DefaultNameFormatter instance

formatHooks

private static final java.util.LinkedList<NameFormatterHook> formatHooks

DEFAULT_NAMING_TAGS_FOR_RELATIONS

public static final java.lang.String[] DEFAULT_NAMING_TAGS_FOR_RELATIONS
The default list of tags which are used as naming tags in relations. A ? prefix indicates a boolean value, for which the key (instead of the value) is used.


namingTagsForRelations

private static java.util.List<java.lang.String> namingTagsForRelations
the current list of tags used as naming tags in relations


nodeComparator

private final java.util.Comparator<Node> nodeComparator

wayComparator

private final java.util.Comparator<Way> wayComparator

relationComparator

private final java.util.Comparator<Relation> relationComparator
Constructor Detail

DefaultNameFormatter

public DefaultNameFormatter()
Method Detail

getInstance

public static DefaultNameFormatter getInstance()
Replies the unique instance of this formatter

Returns:
the unique instance of this formatter

registerFormatHook

public static void registerFormatHook(NameFormatterHook hook)
Registers a format hook. Adds the hook at the first position of the format hooks. (for plugins)

Parameters:
hook - the format hook. Ignored if null.

unregisterFormatHook

public static void unregisterFormatHook(NameFormatterHook hook)
Unregisters a format hook. Removes the hook from the list of format hooks.

Parameters:
hook - the format hook. Ignored if null.

getNamingtagsForRelations

public static java.util.List<java.lang.String> getNamingtagsForRelations()
Replies the list of naming tags used in relations. The list is given (in this order) by:

Returns:
the list of naming tags used in relations

decorateNameWithId

protected void decorateNameWithId(java.lang.StringBuilder name,
                                  IPrimitive primitive)
Decorates the name of primitive with its id, if the preference osm-primitives.showid is set. Shows unique id if osm-primitives.showid.new-primitives is set

Parameters:
name - the name without the id
primitive - the primitive

format

public java.lang.String format(Node node)
Formats a name for a node

Specified by:
format in interface NameFormatter
Parameters:
node - the node
Returns:
the name

getNodeComparator

public java.util.Comparator<Node> getNodeComparator()
Specified by:
getNodeComparator in interface NameFormatter

format

public java.lang.String format(Way way)
Formats a name for a way

Specified by:
format in interface NameFormatter
Parameters:
way - the way
Returns:
the name

getWayComparator

public java.util.Comparator<Way> getWayComparator()
Specified by:
getWayComparator in interface NameFormatter

format

public java.lang.String format(Relation relation)
Formats a name for a relation

Specified by:
format in interface NameFormatter
Parameters:
relation - the relation
Returns:
the name

formatRelationNameAndType

private void formatRelationNameAndType(Relation relation,
                                       java.lang.StringBuilder result,
                                       TaggingPreset preset)

getRelationComparator

public java.util.Comparator<Relation> getRelationComparator()
Specified by:
getRelationComparator in interface NameFormatter

getLeadingNumber

private java.lang.String getLeadingNumber(java.lang.String s)

getRelationTypeName

private java.lang.String getRelationTypeName(IRelation relation)

getNameTagValue

private java.lang.String getNameTagValue(IRelation relation,
                                         java.lang.String nameTag)

getRelationName

private java.lang.String getRelationName(IRelation relation)

format

public java.lang.String format(Changeset changeset)
Formats a name for a changeset

Specified by:
format in interface NameFormatter
Parameters:
changeset - the changeset
Returns:
the name

buildDefaultToolTip

public java.lang.String buildDefaultToolTip(IPrimitive primitive)
Builds a default tooltip text for the primitive primitive.

Parameters:
primitive - the primitmive
Returns:
the tooltip text

decorateNameWithId

protected void decorateNameWithId(java.lang.StringBuilder name,
                                  HistoryOsmPrimitive primitive)
Decorates the name of primitive with its id, if the preference osm-primitives.showid is set. The id is append to the StringBuilder passed in in name.

Parameters:
name - the name without the id
primitive - the primitive

format

public java.lang.String format(HistoryNode node)
Formats a name for a history node

Specified by:
format in interface HistoryNameFormatter
Parameters:
node - the node
Returns:
the name

format

public java.lang.String format(HistoryWay way)
Formats a name for a way

Specified by:
format in interface HistoryNameFormatter
Parameters:
way - the way
Returns:
the name

format

public java.lang.String format(HistoryRelation relation)
Formats a name for a HistoryRelation)

Specified by:
format in interface HistoryNameFormatter
Parameters:
relation - the relation
Returns:
the name

buildDefaultToolTip

public java.lang.String buildDefaultToolTip(HistoryOsmPrimitive primitive)
Builds a default tooltip text for an HistoryOsmPrimitive primitive.

Parameters:
primitive - the primitmive
Returns:
the tooltip text

formatAsHtmlUnorderedList

public java.lang.String formatAsHtmlUnorderedList(java.util.Collection<? extends OsmPrimitive> primitives)

formatAsHtmlUnorderedList

public java.lang.String formatAsHtmlUnorderedList(OsmPrimitive... primitives)


JOSM