Changeset 13122 in josm for trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java
- Timestamp:
- 2017-11-14T01:41:49+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java
r13118 r13122 17 17 import java.util.Collections; 18 18 import java.util.List; 19 import java.util.regex.Pattern; 19 20 20 21 import javax.swing.Action; … … 58 59 public class NoteLayer extends AbstractModifiableLayer implements MouseListener, NoteDataUpdateListener { 59 60 61 /** 62 * Pattern to detect end of sentences followed by another one, or a link, in western script. 63 * Group 1 (capturing): period, interrogation mark, exclamation mark 64 * Group non capturing: at least one horizontal or vertical whitespace 65 * Group 2 (capturing): a letter (any script), or any punctuation 66 */ 67 private static final Pattern SENTENCE_MARKS_WESTERN = Pattern.compile("([\\.\\?\\!])(?:[\\h\\v]+)([\\p{L}\\p{Punct}])"); 68 69 /** 70 * Pattern to detect end of sentences followed by another one, or a link, in eastern script. 71 * Group 1 (capturing): ideographic full stop 72 * Group 2 (capturing): a letter (any script), or any punctuation 73 */ 74 private static final Pattern SENTENCE_MARKS_EASTERN = Pattern.compile("(\\u3002)([\\p{L}\\p{Punct}])"); 75 60 76 private final NoteData noteData; 61 77 … … 205 221 Dimension d = displayedPanel.getPreferredSize(); 206 222 if (d.width > mv.getWidth() / 2) { 207 // To make sure long notes such as https://www.openstreetmap.org/note/278197 are displayed correctly 208 displayedPanel.setText(text.replaceAll("\\. ([\\p{Lower}\\p{Upper}\\p{Punct}])", "\\.<br>$1")); 209 } 223 // To make sure long notes are displayed correctly 224 displayedPanel.setText(insertLineBreaks(text)); 225 } 226 } 227 228 /** 229 * Inserts HTML line breaks ({@code <br>} at the end of each sentence mark 230 * (period, interrogation mark, exclamation mark, ideographic full stop). 231 * @param longText a long text that does not fit on a single line without exceeding half of the map view 232 * @return text with line breaks 233 */ 234 static String insertLineBreaks(String longText) { 235 return SENTENCE_MARKS_WESTERN.matcher(SENTENCE_MARKS_EASTERN.matcher(longText).replaceAll("$1<br>$2")).replaceAll("$1<br>$2"); 210 236 } 211 237
Note:
See TracChangeset
for help on using the changeset viewer.