Changeset 16950 in josm
- Timestamp:
- 2020-08-28T22:38:19+02:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DefaultNameFormatter.java
r16937 r16950 7 7 import static org.openstreetmap.josm.tools.I18n.trn; 8 8 9 import java.awt.ComponentOrientation; 9 10 import java.util.ArrayList; 10 11 import java.util.Arrays; … … 15 16 import java.util.LinkedList; 16 17 import java.util.List; 18 import java.util.Locale; 17 19 import java.util.Map; 18 20 import java.util.Objects; … … 42 44 */ 43 45 public class DefaultNameFormatter implements NameFormatter, HistoryNameFormatter { 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'; 46 52 47 private static DefaultNameFormatter instance; 53 48 … … 147 142 primitive.getUniqueId() : primitive.getId(); 148 143 if (Config.getPref().getBoolean("osm-primitives.showversion") && version > 0) { 149 bdi(name,tr(" [id: {0}, v{1}]", id, version));144 name.append(tr(" [id: {0}, v{1}]", id, version)); 150 145 } else { 151 bdi(name,tr(" [id: {0}]", id));146 name.append(tr(" [id: {0}]", id)); 152 147 } 153 148 } else if (Config.getPref().getBoolean("osm-primitives.showversion")) { 154 bdi(name,tr(" [v{0}]", version));149 name.append(tr(" [v{0}]", version)); 155 150 } 156 151 } … … 211 206 n = node.isNew() ? tr("node") : Long.toString(node.getId()); 212 207 } 213 bdi(name,n);208 name.append(n); 214 209 } else { 215 210 preset.nameTemplate.appendText(name, (TemplateEngineDataProvider) node); 216 211 } 217 212 if (node.isLatLonKnown() && Config.getPref().getBoolean("osm-primitives.showcoor")) { 218 name.append(' '); 219 bdiParen(name, CoordinateFormatManager.getDefaultFormat().toString(node, ", ")); 213 name.append(" \u200E("); 214 name.append(CoordinateFormatManager.getDefaultFormat().toString(node, ", ")); 215 name.append(')'); 220 216 } 221 217 } … … 239 235 public String format(IWay<?> way) { 240 236 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-left 242 mark = '\u200E'; 243 } else { 244 // otherwise will insert Right-To-Left Mark to ensure proper display in the opposite case 245 mark = '\u200F'; 246 } 247 // Initialize base direction of the string 248 name.append(mark); 249 241 250 if (way.isIncomplete()) { 242 251 name.append(tr("incomplete")); … … 284 293 } 285 294 286 bdi(name,n);295 name.append(n); 287 296 } else { 288 297 preset.nameTemplate.appendText(name, (TemplateEngineDataProvider) way); … … 294 303 /* I18n: count of nodes as parameter */ 295 304 String nodes = trn("{0} node", "{0} nodes", nodesNo, nodesNo); 296 name.append(" "); 297 bdiParen(name, nodes); 305 name.append(mark).append(" (").append(nodes).append(')'); 298 306 } 299 307 decorateNameWithId(name, way); … … 635 643 636 644 /** 637 * Wraps the content in a bidirectional isolate638 * @param builder the builder to append to639 * @param content the text to wrap640 */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 isolate649 * @param builder the builder to append to650 * @param content the text to wrap651 */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 /**661 645 * Builds a default tooltip text for an HistoryOsmPrimitive <code>primitive</code>. 662 646 * -
trunk/src/org/openstreetmap/josm/gui/datatransfer/PrimitiveTransferable.java
r16937 r16950 91 91 sb.append(OsmPrimitiveType.from(primitive).getAPIName()).append(' ').append(primitive.getId()); 92 92 } 93 return sb.toString(); 93 return sb.toString().replace("\u200E", "").replace("\u200F", ""); 94 94 } 95 95 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
r16947 r16950 129 129 try { 130 130 for (IPrimitive osm : sel) { 131 String heading = tr("Styles for \"{0}\":", osm.getDisplayName(DefaultNameFormatter.getInstance()) 132 .replace(Character.toString(DefaultNameFormatter.BIDI_FIRST_STRONG_ISOLATE), "") 133 .replace(Character.toString(DefaultNameFormatter.BIDI_POP_DIRECTIONAL_ISOLATE), "")); 131 String heading = tr("Styles for \"{0}\":", osm.getDisplayName(DefaultNameFormatter.getInstance())); 134 132 txtMappaint.println(heading); 135 133 txtMappaint.println(repeatString("=", heading.length())); -
trunk/test/unit/org/openstreetmap/josm/data/osm/DefaultNameFormatterTest.java
r16937 r16950 124 124 @Test 125 125 public void testWayName() { 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")); 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")); 134 130 } 135 131 136 132 static String getFormattedRelationName(String tagsString) { 137 return DefaultNameFormatter.getInstance().format((Relation) OsmUtils.createPrimitive("relation " + tagsString)); 133 return DefaultNameFormatter.getInstance().format((Relation) OsmUtils.createPrimitive("relation " + tagsString)) 134 .replace("\u200E", "").replace("\u200F", ""); 138 135 } 139 136 140 137 static String getFormattedWayName(String tagsString) { 141 return DefaultNameFormatter.getInstance().format((Way) OsmUtils.createPrimitive("way " + tagsString)); 138 return DefaultNameFormatter.getInstance().format((Way) OsmUtils.createPrimitive("way " + tagsString)) 139 .replace("\u200E", "").replace("\u200F", ""); 142 140 } 143 141 … … 152 150 List<Node> nodes = IntStream.rangeClosed(1, 10).mapToObj(i -> new Node(i, 1)) 153 151 .collect(Collectors.toList()); 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>", 152 assertEquals("<ul><li>1</li><li>2</li><li>3</li><li>4</li><li>...</li></ul>", 160 153 DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(nodes, 5)); 161 154 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/util/MultipleNameVisitorTest.java
r16947 r16950 33 33 MultipleNameVisitor visitor = new MultipleNameVisitor(); 34 34 visitor.visit(Arrays.asList(new Way(), new Way())); 35 assertEquals("2 ways: \u20680\u2069 \u2068(0 nodes)\u2069, \u20680\u2069 \u2068(0 nodes)\u2069", visitor.toString());35 assertEquals("2 ways: 0 (0 nodes), 0 (0 nodes)", visitor.toString()); 36 36 } 37 37 … … 46 46 TestUtils.newWay("addr:housename=Stark"), 47 47 TestUtils.newRelation("type=route"))); 48 assertEquals("3 objects: \u2068foo\u2069, \u2068House Stark\u2069 \u2068(0 nodes)\u2069, route (0, 0 members)", visitor.toString());48 assertEquals("3 objects: foo, House Stark (0 nodes), route (0, 0 members)", visitor.toString()); 49 49 } 50 50 }
Note:
See TracChangeset
for help on using the changeset viewer.