Changeset 16937 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DefaultNameFormatter.java
r16824 r16937 7 7 import static org.openstreetmap.josm.tools.I18n.trn; 8 8 9 import java.awt.ComponentOrientation;10 9 import java.util.ArrayList; 11 10 import java.util.Arrays; … … 16 15 import java.util.LinkedList; 17 16 import java.util.List; 18 import java.util.Locale;19 17 import java.util.Map; 20 18 import java.util.Objects; … … 44 42 */ 45 43 public class DefaultNameFormatter implements NameFormatter, HistoryNameFormatter { 46 44 /** 45 * U+2068 FIRST STRONG ISOLATE 46 */ 47 public static final char BIDI_FIRST_STRONG_ISOLATE = '\u2068'; 48 /** 49 * U+2069 POP DIRECTIONAL ISOLATE 50 */ 51 public static final char BIDI_POP_DIRECTIONAL_ISOLATE = '\u2069'; 47 52 private static DefaultNameFormatter instance; 48 53 … … 142 147 primitive.getUniqueId() : primitive.getId(); 143 148 if (Config.getPref().getBoolean("osm-primitives.showversion") && version > 0) { 144 name.append(tr(" [id: {0}, v{1}]", id, version));149 bdi(name, tr(" [id: {0}, v{1}]", id, version)); 145 150 } else { 146 name.append(tr(" [id: {0}]", id));151 bdi(name, tr(" [id: {0}]", id)); 147 152 } 148 153 } else if (Config.getPref().getBoolean("osm-primitives.showversion")) { 149 name.append(tr(" [v{0}]", version));154 bdi(name, tr(" [v{0}]", version)); 150 155 } 151 156 } … … 206 211 n = node.isNew() ? tr("node") : Long.toString(node.getId()); 207 212 } 208 name.append(n);213 bdi(name, n); 209 214 } else { 210 215 preset.nameTemplate.appendText(name, (TemplateEngineDataProvider) node); 211 216 } 212 217 if (node.isLatLonKnown() && Config.getPref().getBoolean("osm-primitives.showcoor")) { 213 name.append(" \u200E("); 214 name.append(CoordinateFormatManager.getDefaultFormat().toString(node, ", ")); 215 name.append(')'); 218 name.append(' '); 219 bdiParen(name, CoordinateFormatManager.getDefaultFormat().toString(node, ", ")); 216 220 } 217 221 } … … 235 239 public String format(IWay<?> way) { 236 240 StringBuilder name = new StringBuilder(); 237 238 char mark;239 // If current language is left-to-right (almost all languages)240 if (ComponentOrientation.getOrientation(Locale.getDefault()).isLeftToRight()) {241 // will insert Left-To-Right Mark to ensure proper display of text in the case when object name is right-to-left242 mark = '\u200E';243 } else {244 // otherwise will insert Right-To-Left Mark to ensure proper display in the opposite case245 mark = '\u200F';246 }247 // Initialize base direction of the string248 name.append(mark);249 250 241 if (way.isIncomplete()) { 251 242 name.append(tr("incomplete")); … … 293 284 } 294 285 295 name.append(n);286 bdi(name, n); 296 287 } else { 297 288 preset.nameTemplate.appendText(name, (TemplateEngineDataProvider) way); … … 303 294 /* I18n: count of nodes as parameter */ 304 295 String nodes = trn("{0} node", "{0} nodes", nodesNo, nodesNo); 305 name.append(mark).append(" (").append(nodes).append(')'); 296 name.append(" "); 297 bdiParen(name, nodes); 306 298 } 307 299 decorateNameWithId(name, way); … … 643 635 644 636 /** 637 * Wraps the content in a bidirectional isolate 638 * @param builder the builder to append to 639 * @param content the text to wrap 640 */ 641 private static void bdi(StringBuilder builder, String content) { 642 builder.append(BIDI_FIRST_STRONG_ISOLATE); 643 builder.append(content); 644 builder.append(BIDI_POP_DIRECTIONAL_ISOLATE); 645 } 646 647 /** 648 * Wraps the content in parenthesis and a bidirectional isolate 649 * @param builder the builder to append to 650 * @param content the text to wrap 651 */ 652 private static void bdiParen(StringBuilder builder, String content) { 653 builder.append(BIDI_FIRST_STRONG_ISOLATE); 654 builder.append('('); 655 builder.append(content); 656 builder.append(')'); 657 builder.append(BIDI_POP_DIRECTIONAL_ISOLATE); 658 } 659 660 /** 645 661 * Builds a default tooltip text for an HistoryOsmPrimitive <code>primitive</code>. 646 662 * -
trunk/src/org/openstreetmap/josm/gui/datatransfer/PrimitiveTransferable.java
r16326 r16937 91 91 sb.append(OsmPrimitiveType.from(primitive).getAPIName()).append(' ').append(primitive.getId()); 92 92 } 93 return sb.toString() .replace("\u200E", "").replace("\u200F", "");93 return sb.toString(); 94 94 } 95 95 } -
trunk/test/unit/org/openstreetmap/josm/data/osm/DefaultNameFormatterTest.java
r16445 r16937 124 124 @Test 125 125 public void testWayName() { 126 assertEquals("building (0 nodes)", getFormattedWayName("building=yes")); 127 assertEquals("House number 123 (0 nodes)", getFormattedWayName("building=yes addr:housenumber=123")); 128 assertEquals("House number 123 at FooStreet (0 nodes)", getFormattedWayName("building=yes addr:housenumber=123 addr:street=FooStreet")); 129 assertEquals("House FooName (0 nodes)", getFormattedWayName("building=yes addr:housenumber=123 addr:housename=FooName")); 126 assertEquals("\u2068building\u2069 \u2068(0 nodes)\u2069", 127 getFormattedWayName("building=yes")); 128 assertEquals("\u2068House number 123\u2069 \u2068(0 nodes)\u2069", 129 getFormattedWayName("building=yes addr:housenumber=123")); 130 assertEquals("\u2068House number 123 at FooStreet\u2069 \u2068(0 nodes)\u2069", 131 getFormattedWayName("building=yes addr:housenumber=123 addr:street=FooStreet")); 132 assertEquals("\u2068House FooName\u2069 \u2068(0 nodes)\u2069", 133 getFormattedWayName("building=yes addr:housenumber=123 addr:housename=FooName")); 130 134 } 131 135 132 136 static String getFormattedRelationName(String tagsString) { 133 return DefaultNameFormatter.getInstance().format((Relation) OsmUtils.createPrimitive("relation " + tagsString)) 134 .replace("\u200E", "").replace("\u200F", ""); 137 return DefaultNameFormatter.getInstance().format((Relation) OsmUtils.createPrimitive("relation " + tagsString)); 135 138 } 136 139 137 140 static String getFormattedWayName(String tagsString) { 138 return DefaultNameFormatter.getInstance().format((Way) OsmUtils.createPrimitive("way " + tagsString)) 139 .replace("\u200E", "").replace("\u200F", ""); 141 return DefaultNameFormatter.getInstance().format((Way) OsmUtils.createPrimitive("way " + tagsString)); 140 142 } 141 143 … … 150 152 List<Node> nodes = IntStream.rangeClosed(1, 10).mapToObj(i -> new Node(i, 1)) 151 153 .collect(Collectors.toList()); 152 assertEquals("<ul><li>1</li><li>2</li><li>3</li><li>4</li><li>...</li></ul>", 154 assertEquals("<ul>" + 155 "<li>\u20681\u2069</li>" + 156 "<li>\u20682\u2069</li>" + 157 "<li>\u20683\u2069</li>" + 158 "<li>\u20684\u2069</li>" + 159 "<li>...</li></ul>", 153 160 DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(nodes, 5)); 154 161 }
Note:
See TracChangeset
for help on using the changeset viewer.