Package org.openstreetmap.josm.data.osm
Class DefaultNameFormatter
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.DefaultNameFormatter
-
- All Implemented Interfaces:
HistoryNameFormatter
,NameFormatter
public class DefaultNameFormatter extends java.lang.Object implements NameFormatter, HistoryNameFormatter
This is the default implementation of aNameFormatter
for names ofIPrimitive
s andHistoryOsmPrimitive
s.- Since:
- 12663 (moved from
gui
package), 1990
-
-
Field Summary
Fields Modifier and Type Field Description private 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.List<NameFormatterHook>
formatHooks
private static java.util.List<java.lang.String>
HIGHWAY_RAILWAY_WATERWAY_LANDUSE_BUILDING
private static DefaultNameFormatter
instance
private static java.util.List<java.lang.String>
namingTagsForRelations
the current list of tags used as naming tags in relationsprivate java.util.Comparator<INode>
nodeComparator
private static CachingProperty<java.lang.Boolean>
PROPERTY_LOCALIZE_NAME
private static CachingProperty<java.lang.Boolean>
PROPERTY_SHOW_COOR
private static CachingProperty<java.lang.Boolean>
PROPERTY_SHOW_ID
private static CachingProperty<java.lang.Boolean>
PROPERTY_SHOW_ID_NEW_PRIMITIVES
private static CachingProperty<java.lang.Boolean>
PROPERTY_SHOW_VERSION
private java.util.Comparator<IRelation<?>>
relationComparator
private java.util.Comparator<IWay<?>>
wayComparator
-
Constructor Summary
Constructors Constructor Description DefaultNameFormatter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
buildDefaultToolTip(long id, java.util.Map<java.lang.String,java.lang.String> tags)
java.lang.String
buildDefaultToolTip(HistoryOsmPrimitive primitive)
Builds a default tooltip text for an HistoryOsmPrimitiveprimitive
.java.lang.String
buildDefaultToolTip(IPrimitive primitive)
Builds a default tooltip text for the primitiveprimitive
.protected void
decorateNameWithId(java.lang.StringBuilder name, HistoryOsmPrimitive primitive)
Decorates the name of primitive with its id, if the preferenceosm-primitives.showid
is set.protected void
decorateNameWithId(java.lang.StringBuilder name, IPrimitive primitive)
Decorates the name of primitive with its id and version, if the preferencesosm-primitives.showid
andosm-primitives.showversion
are set.protected void
decorateNameWithNodes(java.lang.StringBuilder name, IWay<?> way)
Decorates the name of primitive with nodes countjava.lang.String
format(Changeset changeset)
Formats a name for aChangeset
.java.lang.String
format(HistoryNode node)
Formats a name for aHistoryNode
.java.lang.String
format(HistoryRelation relation)
Formats a name for aHistoryRelation
.java.lang.String
format(HistoryWay way)
Formats a name for aHistoryWay
.java.lang.String
format(INode node)
Formats a name for aINode
.java.lang.String
format(IPrimitive osm)
Formats a name for anIPrimitive
.java.lang.String
format(IRelation<?> relation)
Formats a name for aIRelation
.java.lang.String
format(IWay<?> way)
Formats a name for aIWay
.private static java.lang.String
formatAddress(Tagged osm)
java.lang.String
formatAsHtmlUnorderedList(java.util.Collection<? extends OsmPrimitive> primitives, int maxElements)
Formats the given collection of primitives as an HTML unordered list.java.lang.String
formatAsHtmlUnorderedList(OsmPrimitive primitive)
Formats the given primitive as an HTML unordered list.private static java.lang.String
formatLocalName(HistoryOsmPrimitive osm)
private static java.lang.String
formatLocalName(IPrimitive osm)
private static java.lang.StringBuilder
formatRelationNameAndType(IRelation<?> relation, java.lang.StringBuilder result, TaggingPreset preset)
static DefaultNameFormatter
getInstance()
Replies the unique instance of this formatterprivate static 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<INode>
getNodeComparator()
Gets a comparator that sorts the nodes by the string that this formatter would create for themjava.util.Comparator<IRelation<?>>
getRelationComparator()
Gets a comparator that sorts the relations by the string that this formatter would create for themprivate static java.lang.String
getRelationName(IRelation<?> relation)
private static java.lang.String
getRelationTypeName(IRelation<?> relation)
java.util.Comparator<IWay<?>>
getWayComparator()
Gets a comparator that sorts the ways by the string that this formatter would create for themstatic void
registerFormatHook(NameFormatterHook hook)
Registers a format hook.static java.lang.String
removeBiDiCharacters(java.lang.String string)
Removes the bidirectional text characters U+200C, U+200E, U+200F from the stringstatic void
unregisterFormatHook(NameFormatterHook hook)
Unregisters a format hook.
-
-
-
Field Detail
-
instance
private static DefaultNameFormatter instance
-
formatHooks
private static final java.util.List<NameFormatterHook> formatHooks
-
PROPERTY_SHOW_ID
private static final CachingProperty<java.lang.Boolean> PROPERTY_SHOW_ID
-
PROPERTY_SHOW_ID_NEW_PRIMITIVES
private static final CachingProperty<java.lang.Boolean> PROPERTY_SHOW_ID_NEW_PRIMITIVES
-
PROPERTY_SHOW_VERSION
private static final CachingProperty<java.lang.Boolean> PROPERTY_SHOW_VERSION
-
PROPERTY_SHOW_COOR
private static final CachingProperty<java.lang.Boolean> PROPERTY_SHOW_COOR
-
PROPERTY_LOCALIZE_NAME
private static final CachingProperty<java.lang.Boolean> PROPERTY_LOCALIZE_NAME
-
HIGHWAY_RAILWAY_WATERWAY_LANDUSE_BUILDING
private static final java.util.List<java.lang.String> HIGHWAY_RAILWAY_WATERWAY_LANDUSE_BUILDING
-
DEFAULT_NAMING_TAGS_FOR_RELATIONS
private 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<INode> nodeComparator
-
wayComparator
private final java.util.Comparator<IWay<?>> wayComparator
-
relationComparator
private final java.util.Comparator<IRelation<?>> 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:- by the tag names in the preference
relation.nameOrder
- by the default tags in
DEFAULT_NAMING_TAGS_FOR_RELATIONS
- Returns:
- the list of naming tags used in relations
- by the tag names in the preference
-
decorateNameWithId
protected void decorateNameWithId(java.lang.StringBuilder name, IPrimitive primitive)
Decorates the name of primitive with its id and version, if the preferencesosm-primitives.showid
andosm-primitives.showversion
are set. Shows unique id ifosm-primitives.showid.new-primitives
is set- Parameters:
name
- the name without the idprimitive
- the primitive
-
decorateNameWithNodes
protected void decorateNameWithNodes(java.lang.StringBuilder name, IWay<?> way)
Decorates the name of primitive with nodes count- Parameters:
name
- the name without the nodes countway
- the way- Since:
- 18808
-
format
public java.lang.String format(IPrimitive osm)
Formats a name for anIPrimitive
.- Parameters:
osm
- the primitive- Returns:
- the name
- Since:
- 10991, 13564 (signature)
-
format
public java.lang.String format(INode node)
Description copied from interface:NameFormatter
Formats a name for aINode
.- Specified by:
format
in interfaceNameFormatter
- Parameters:
node
- the node- Returns:
- the name
-
getNodeComparator
public java.util.Comparator<INode> getNodeComparator()
Description copied from interface:NameFormatter
Gets a comparator that sorts the nodes by the string that this formatter would create for them- Specified by:
getNodeComparator
in interfaceNameFormatter
- Returns:
- That comparator
-
format
public java.lang.String format(IWay<?> way)
Description copied from interface:NameFormatter
Formats a name for aIWay
.- Specified by:
format
in interfaceNameFormatter
- Parameters:
way
- the way- Returns:
- the name
-
formatLocalName
private static java.lang.String formatLocalName(IPrimitive osm)
-
formatLocalName
private static java.lang.String formatLocalName(HistoryOsmPrimitive osm)
-
formatAddress
private static java.lang.String formatAddress(Tagged osm)
-
getWayComparator
public java.util.Comparator<IWay<?>> getWayComparator()
Description copied from interface:NameFormatter
Gets a comparator that sorts the ways by the string that this formatter would create for them- Specified by:
getWayComparator
in interfaceNameFormatter
- Returns:
- That comparator
-
format
public java.lang.String format(IRelation<?> relation)
Description copied from interface:NameFormatter
Formats a name for aIRelation
.- Specified by:
format
in interfaceNameFormatter
- Parameters:
relation
- the relation- Returns:
- the name
-
formatRelationNameAndType
private static java.lang.StringBuilder formatRelationNameAndType(IRelation<?> relation, java.lang.StringBuilder result, TaggingPreset preset)
-
getRelationComparator
public java.util.Comparator<IRelation<?>> getRelationComparator()
Description copied from interface:NameFormatter
Gets a comparator that sorts the relations by the string that this formatter would create for them- Specified by:
getRelationComparator
in interfaceNameFormatter
- Returns:
- That comparator
-
getRelationTypeName
private static java.lang.String getRelationTypeName(IRelation<?> relation)
-
getNameTagValue
private static java.lang.String getNameTagValue(IRelation<?> relation, java.lang.String nameTag)
-
getRelationName
private static java.lang.String getRelationName(IRelation<?> relation)
-
format
public java.lang.String format(Changeset changeset)
Description copied from interface:NameFormatter
Formats a name for aChangeset
.- Specified by:
format
in interfaceNameFormatter
- Parameters:
changeset
- the changeset- Returns:
- the name
-
buildDefaultToolTip
public java.lang.String buildDefaultToolTip(IPrimitive primitive)
Builds a default tooltip text for the primitiveprimitive
.- Parameters:
primitive
- the primitive- Returns:
- the tooltip text
-
buildDefaultToolTip
private static java.lang.String buildDefaultToolTip(long id, java.util.Map<java.lang.String,java.lang.String> tags)
-
decorateNameWithId
protected void decorateNameWithId(java.lang.StringBuilder name, HistoryOsmPrimitive primitive)
Decorates the name of primitive with its id, if the preferenceosm-primitives.showid
is set.The id is appended to the
StringBuilder
passed inname
.- Parameters:
name
- the name without the idprimitive
- the primitive
-
format
public java.lang.String format(HistoryNode node)
Description copied from interface:HistoryNameFormatter
Formats a name for aHistoryNode
.- Specified by:
format
in interfaceHistoryNameFormatter
- Parameters:
node
- the node- Returns:
- the name
-
format
public java.lang.String format(HistoryWay way)
Description copied from interface:HistoryNameFormatter
Formats a name for aHistoryWay
.- Specified by:
format
in interfaceHistoryNameFormatter
- Parameters:
way
- the way- Returns:
- the name
-
format
public java.lang.String format(HistoryRelation relation)
Description copied from interface:HistoryNameFormatter
Formats a name for aHistoryRelation
.- Specified by:
format
in interfaceHistoryNameFormatter
- Parameters:
relation
- the relation- Returns:
- the name
-
buildDefaultToolTip
public java.lang.String buildDefaultToolTip(HistoryOsmPrimitive primitive)
Builds a default tooltip text for an HistoryOsmPrimitiveprimitive
.- Parameters:
primitive
- the primitive- Returns:
- the tooltip text
-
formatAsHtmlUnorderedList
public java.lang.String formatAsHtmlUnorderedList(java.util.Collection<? extends OsmPrimitive> primitives, int maxElements)
Formats the given collection of primitives as an HTML unordered list.- Parameters:
primitives
- collection of primitives to formatmaxElements
- the maximum number of elements to display- Returns:
- HTML unordered list
-
formatAsHtmlUnorderedList
public java.lang.String formatAsHtmlUnorderedList(OsmPrimitive primitive)
Formats the given primitive as an HTML unordered list.- Parameters:
primitive
- primitive to format- Returns:
- HTML unordered list
-
removeBiDiCharacters
public static java.lang.String removeBiDiCharacters(java.lang.String string)
Removes the bidirectional text characters U+200C, U+200E, U+200F from the string- Parameters:
string
- the string- Returns:
- the string with the bidirectional text characters removed
-
-