Changeset 13122 in josm


Ignore:
Timestamp:
2017-11-14T01:41:49+01:00 (5 days ago)
Author:
Don-vip
Message:

fix #15550 - Automatic line break of note tooltips (tested on western and ideographic scripts)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/netbeans/nbproject/project.properties

    r13112 r13122  
    9595    ${file.reference.system-rules-1.16.1.jar}:\
    9696    ${file.reference.wiremock-standalone-2.10.1.jar}:\
    97         ${file.reference.awaitility-3.0.0.jar}:\
     97    ${file.reference.awaitility-3.0.0.jar}:\
    9898    ${file.reference.spotbugs.jar}:\
    9999    ${file.reference.commons-testing-2.1.0.jar}
  • trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java

    r13118 r13122  
    1717import java.util.Collections;
    1818import java.util.List;
     19import java.util.regex.Pattern;
    1920
    2021import javax.swing.Action;
     
    5859public class NoteLayer extends AbstractModifiableLayer implements MouseListener, NoteDataUpdateListener {
    5960
     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
    6076    private final NoteData noteData;
    6177
     
    205221        Dimension d = displayedPanel.getPreferredSize();
    206222        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");
    210236    }
    211237
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/NoteLayerTest.java

    r10650 r13122  
    44import static org.junit.Assert.assertEquals;
    55
    6 import org.junit.BeforeClass;
     6import org.junit.Rule;
    77import org.junit.Test;
    8 import org.openstreetmap.josm.JOSMFixture;
     8import org.openstreetmap.josm.testutils.JOSMTestRules;
     9
     10import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    911
    1012/**
     
    1618     * Setup tests
    1719     */
    18     @BeforeClass
    19     public static void setUpBeforeClass() {
    20         JOSMFixture.createUnitTestFixture().init();
    21     }
     20    @Rule
     21    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     22    public JOSMTestRules test = new JOSMTestRules();
    2223
    2324    /**
     
    2829        assertEquals("0 notes", new NoteLayer().getToolTipText());
    2930    }
     31
     32    /**
     33     * Unit test of {@link NoteLayer#insertLineBreaks}.
     34     */
     35    @Test
     36    public void testInsertLineBreaks() {
     37        // empty string
     38        assertEquals("", NoteLayer.insertLineBreaks(""));
     39        // CHECKSTYLE.OFF: LineLength
     40        // https://www.openstreetmap.org/note/278197: long text with periods
     41        assertEquals("<html>Note 278197<hr/>Klumbumbus on Nov 29, 2014:<br>Hier soll eine zusätzliche Rechtsabbiegerspur entstehen.<br>Müsste dann bei Fertigstellung nochmal geprüft und die lanes angepoasst werden.<br><a href=\"http://www.sachsen-fernsehen.de/Aktuell/Chemnitz/Artikel/1370077/Bauarbeiten-auf-Chemnitzer-Hartmannstrasse-beginnen/\">http://www.sachsen-fernsehen.de/Aktuell/Chemnitz/Artikel/1370077/Bauarbeiten-auf-Chemnitzer-Hartmannstrasse-beginnen/</a><hr/>Saxonyking on May 4, 2015:<br>Danke<br>eingetragen</html>",
     42                NoteLayer.insertLineBreaks(
     43                     "<html>Note 278197<hr/>Klumbumbus on Nov 29, 2014:<br>Hier soll eine zusätzliche Rechtsabbiegerspur entstehen. Müsste dann bei Fertigstellung nochmal geprüft und die lanes angepoasst werden. <a href=\"http://www.sachsen-fernsehen.de/Aktuell/Chemnitz/Artikel/1370077/Bauarbeiten-auf-Chemnitzer-Hartmannstrasse-beginnen/\">http://www.sachsen-fernsehen.de/Aktuell/Chemnitz/Artikel/1370077/Bauarbeiten-auf-Chemnitzer-Hartmannstrasse-beginnen/</a><hr/>Saxonyking on May 4, 2015:<br>Danke<br>eingetragen</html>"));
     44        // https://www.openstreetmap.org/note/1196942: long text without periods (question marks instead)
     45        assertEquals("<html>Note 1196942<hr/>Mateusz Konieczny on Nov 6, 2017:<br><a href=\"https://www.openstreetmap.org/way/51661050#map=17/50.9326393/14.0821931layers=N\">https://www.openstreetmap.org/way/51661050#map=17/50.9326393/14.0821931layers=N</a> Why this is not tagged as highway=steps?<br>What is the meaning of steps=yes here?<br>See <a href=\"http://overpass-turbo.eu/s/sLv\">http://overpass-turbo.eu/s/sLv</a> for more cases (I considered armchair mapping it to highway=steps but I think that verification from local mappers is preferable)</html>",
     46                NoteLayer.insertLineBreaks(
     47                     "<html>Note 1196942<hr/>Mateusz Konieczny on Nov 6, 2017:<br><a href=\"https://www.openstreetmap.org/way/51661050#map=17/50.9326393/14.0821931layers=N\">https://www.openstreetmap.org/way/51661050#map=17/50.9326393/14.0821931layers=N</a> Why this is not tagged as highway=steps? What is the meaning of steps=yes here? See <a href=\"http://overpass-turbo.eu/s/sLv\">http://overpass-turbo.eu/s/sLv</a> for more cases (I considered armchair mapping it to highway=steps but I think that verification from local mappers is preferable)</html>"));
     48        // https://www.openstreetmap.org/note/1029364: several spaces between sentence mark and next sentence
     49        assertEquals("<html>Note 1029364<hr/>SaGm on Jun 13, 2017:<br>HOW CAN I CONNECT THIS ROUD TO THE MAIN ROUDS?<br><br>if i make a GPX trail its SKIP this way.<br><hr/>dsh4 on Jun 14, 2017:<br>To connect roads, they need to have a node in common.<br>This is already the case here: the footway has nodes in common with Idan and with Katsenelson.<br>Thus, in that respect, the map is correct.<br>If your router doesn't use the new footway, it would be better to ask about that elsewhere, see <a href=\"http://wiki.openstreetmap.org/wiki/Contact_channels\">http://wiki.openstreetmap.org/wiki/Contact_channels</a> .<br>(Notes are only really suited for discussing errors in the map, and there isn't an error in the map here.)<br><br>The footway is also a member of two turn restrictions that forbid turning from Katsenelson onto the footway.<br>Presumably pedestrians are allowed to enter the footway from Katsenelson, so those restrictions are wrong and should be deleted.<br><br>Cheers!<hr/>SaGm on Jun 14, 2017:<br>Thanks Dsh4<br>How can i delet it?<br><hr/>dsh4 on Jun 14, 2017:<br>That depends on what editor program you use.<br>In JOSM, for example, you would click on the footway, then double-click on the turn restriction in the &quot;Tags / Memberships&quot; window on the right, and then click the trash can button in the pop-up window to delete the entire relation (not just the membership of the footway in the relation).<br>A web search ought to find instructions for your favourite editor as well.</html>",
     50                NoteLayer.insertLineBreaks(
     51                     "<html>Note 1029364<hr/>SaGm on Jun 13, 2017:<br>HOW CAN I CONNECT THIS ROUD TO THE MAIN ROUDS?<br><br>if i make a GPX trail its SKIP this way.<br><hr/>dsh4 on Jun 14, 2017:<br>To connect roads, they need to have a node in common.  This is already the case here: the footway has nodes in common with Idan and with Katsenelson.  Thus, in that respect, the map is correct.  If your router doesn't use the new footway, it would be better to ask about that elsewhere, see <a href=\"http://wiki.openstreetmap.org/wiki/Contact_channels\">http://wiki.openstreetmap.org/wiki/Contact_channels</a> .  (Notes are only really suited for discussing errors in the map, and there isn't an error in the map here.)<br><br>The footway is also a member of two turn restrictions that forbid turning from Katsenelson onto the footway.  Presumably pedestrians are allowed to enter the footway from Katsenelson, so those restrictions are wrong and should be deleted.<br><br>Cheers!<hr/>SaGm on Jun 14, 2017:<br>Thanks Dsh4<br>How can i delet it?<br><hr/>dsh4 on Jun 14, 2017:<br>That depends on what editor program you use.  In JOSM, for example, you would click on the footway, then double-click on the turn restriction in the &quot;Tags / Memberships&quot; window on the right, and then click the trash can button in the pop-up window to delete the entire relation (not just the membership of the footway in the relation).  A web search ought to find instructions for your favourite editor as well.</html>"));
     52        // https://www.openstreetmap.org/note/230617: ideographic full stops
     53        assertEquals("<html>Note 230617<hr/>deckkun on Aug 27, 2014:<br>筑紫が丘への抜け道?<hr/>Rakkka on Jul 20, 2017:<br>地図を修正するためのメモではないように見えますが、解決してもよろしいでしょうか?<hr/>&lt;anonymous&gt; on Jul 21, 2017:<br>そうです。<br>一部未舗装があり、急な坂があります。<br>細い部分もあるので自動車は無理です。<br><hr/>Rakkka on Jul 21, 2017:<br>この地点から北西へ伸びている道路のことですよね。<br>自動車道になっているので、自動車が通れないなら直さないといけませんが、通れない部分がわからないので、メモは残しておきます。<br><hr/>&lt;anonymous&gt; on Jul 21, 2017:<br>そうです。<br>マーク地点からですと白百合学園までは行けますが、そこから筑紫が丘六丁目7に出る付近は資材置き場があり、狭く、もしかしたら一部私有地内の通行になるのかも。<br>軽自動車なら行ける幅だと思いますが。<br>ストリートマップでイメージは掴めると思います。<br></html>",
     54                NoteLayer.insertLineBreaks(
     55                     "<html>Note 230617<hr/>deckkun on Aug 27, 2014:<br>筑紫が丘への抜け道?<hr/>Rakkka on Jul 20, 2017:<br>地図を修正するためのメモではないように見えますが、解決してもよろしいでしょうか?<hr/>&lt;anonymous&gt; on Jul 21, 2017:<br>そうです。一部未舗装があり、急な坂があります。細い部分もあるので自動車は無理です。<hr/>Rakkka on Jul 21, 2017:<br>この地点から北西へ伸びている道路のことですよね。自動車道になっているので、自動車が通れないなら直さないといけませんが、通れない部分がわからないので、メモは残しておきます。<hr/>&lt;anonymous&gt; on Jul 21, 2017:<br>そうです。マーク地点からですと白百合学園までは行けますが、そこから筑紫が丘六丁目7に出る付近は資材置き場があり、狭く、もしかしたら一部私有地内の通行になるのかも。軽自動車なら行ける幅だと思いますが。ストリートマップでイメージは掴めると思います。</html>"));
     56        // CHECKSTYLE.ON: LineLength
     57    }
    3058}
Note: See TracChangeset for help on using the changeset viewer.