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 aNameFormatterfor names ofIPrimitives andHistoryOsmPrimitives.- Since:
- 12663 (moved from
guipackage), 1990
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String[]DEFAULT_NAMING_TAGS_FOR_RELATIONSThe default list of tags which are used as naming tags in relations.private static java.util.List<NameFormatterHook>formatHooksprivate static java.util.List<java.lang.String>HIGHWAY_RAILWAY_WATERWAY_LANDUSE_BUILDINGprivate static DefaultNameFormatterinstanceprivate static java.util.List<java.lang.String>namingTagsForRelationsthe current list of tags used as naming tags in relationsprivate java.util.Comparator<INode>nodeComparatorprivate static CachingProperty<java.lang.Boolean>PROPERTY_LOCALIZE_NAMEprivate static CachingProperty<java.lang.Boolean>PROPERTY_SHOW_COORprivate static CachingProperty<java.lang.Boolean>PROPERTY_SHOW_IDprivate static CachingProperty<java.lang.Boolean>PROPERTY_SHOW_ID_NEW_PRIMITIVESprivate static CachingProperty<java.lang.Boolean>PROPERTY_SHOW_VERSIONprivate java.util.Comparator<IRelation<?>>relationComparatorprivate 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.StringbuildDefaultToolTip(long id, java.util.Map<java.lang.String,java.lang.String> tags)java.lang.StringbuildDefaultToolTip(HistoryOsmPrimitive primitive)Builds a default tooltip text for an HistoryOsmPrimitiveprimitive.java.lang.StringbuildDefaultToolTip(IPrimitive primitive)Builds a default tooltip text for the primitiveprimitive.protected voiddecorateNameWithId(java.lang.StringBuilder name, HistoryOsmPrimitive primitive)Decorates the name of primitive with its id, if the preferenceosm-primitives.showidis set.protected voiddecorateNameWithId(java.lang.StringBuilder name, IPrimitive primitive)Decorates the name of primitive with its id and version, if the preferencesosm-primitives.showidandosm-primitives.showversionare set.protected voiddecorateNameWithNodes(java.lang.StringBuilder name, IWay<?> way)Decorates the name of primitive with nodes countjava.lang.Stringformat(Changeset changeset)Formats a name for aChangeset.java.lang.Stringformat(HistoryNode node)Formats a name for aHistoryNode.java.lang.Stringformat(HistoryRelation relation)Formats a name for aHistoryRelation.java.lang.Stringformat(HistoryWay way)Formats a name for aHistoryWay.java.lang.Stringformat(INode node)Formats a name for aINode.java.lang.Stringformat(IPrimitive osm)Formats a name for anIPrimitive.java.lang.Stringformat(IRelation<?> relation)Formats a name for aIRelation.java.lang.Stringformat(IWay<?> way)Formats a name for aIWay.private static java.lang.StringformatAddress(Tagged osm)java.lang.StringformatAsHtmlUnorderedList(java.util.Collection<? extends OsmPrimitive> primitives, int maxElements)Formats the given collection of primitives as an HTML unordered list.java.lang.StringformatAsHtmlUnorderedList(OsmPrimitive primitive)Formats the given primitive as an HTML unordered list.private static java.lang.StringformatLocalName(HistoryOsmPrimitive osm)private static java.lang.StringformatLocalName(IPrimitive osm)private static java.lang.StringBuilderformatRelationNameAndType(IRelation<?> relation, java.lang.StringBuilder result, TaggingPreset preset)static DefaultNameFormattergetInstance()Replies the unique instance of this formatterprivate static java.lang.StringgetNameTagValue(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.StringgetRelationName(IRelation<?> relation)private static java.lang.StringgetRelationTypeName(IRelation<?> relation)java.util.Comparator<IWay<?>>getWayComparator()Gets a comparator that sorts the ways by the string that this formatter would create for themstatic voidregisterFormatHook(NameFormatterHook hook)Registers a format hook.static java.lang.StringremoveBiDiCharacters(java.lang.String string)Removes the bidirectional text characters U+200C, U+200E, U+200F from the stringstatic voidunregisterFormatHook(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.showidandosm-primitives.showversionare set. Shows unique id ifosm-primitives.showid.new-primitivesis 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:NameFormatterFormats a name for aINode.- Specified by:
formatin interfaceNameFormatter- Parameters:
node- the node- Returns:
- the name
-
getNodeComparator
public java.util.Comparator<INode> getNodeComparator()
Description copied from interface:NameFormatterGets a comparator that sorts the nodes by the string that this formatter would create for them- Specified by:
getNodeComparatorin interfaceNameFormatter- Returns:
- That comparator
-
format
public java.lang.String format(IWay<?> way)
Description copied from interface:NameFormatterFormats a name for aIWay.- Specified by:
formatin 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:NameFormatterGets a comparator that sorts the ways by the string that this formatter would create for them- Specified by:
getWayComparatorin interfaceNameFormatter- Returns:
- That comparator
-
format
public java.lang.String format(IRelation<?> relation)
Description copied from interface:NameFormatterFormats a name for aIRelation.- Specified by:
formatin 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:NameFormatterGets a comparator that sorts the relations by the string that this formatter would create for them- Specified by:
getRelationComparatorin 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:NameFormatterFormats a name for aChangeset.- Specified by:
formatin 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.showidis set.The id is appended to the
StringBuilderpassed inname.- Parameters:
name- the name without the idprimitive- the primitive
-
format
public java.lang.String format(HistoryNode node)
Description copied from interface:HistoryNameFormatterFormats a name for aHistoryNode.- Specified by:
formatin interfaceHistoryNameFormatter- Parameters:
node- the node- Returns:
- the name
-
format
public java.lang.String format(HistoryWay way)
Description copied from interface:HistoryNameFormatterFormats a name for aHistoryWay.- Specified by:
formatin interfaceHistoryNameFormatter- Parameters:
way- the way- Returns:
- the name
-
format
public java.lang.String format(HistoryRelation relation)
Description copied from interface:HistoryNameFormatterFormats a name for aHistoryRelation.- Specified by:
formatin 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
-
-