Changeset 16322 in josm for trunk


Ignore:
Timestamp:
2020-04-17T20:50:39+02:00 (5 years ago)
Author:
simon04
Message:

fix #18883 - InspectPrimitiveDialog: improve mapstyle summary

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r14153 r16322  
    77import java.awt.Dimension;
    88import java.awt.GridBagLayout;
     9import java.io.PrintWriter;
     10import java.io.StringWriter;
    911import java.text.Collator;
    1012import java.util.ArrayList;
     
    118120        double scale = nc.getDist100Pixel();
    119121
    120         final StringBuilder txtMappaint = new StringBuilder();
     122        final StringWriter stringWriter = new StringWriter();
     123        final PrintWriter txtMappaint = new PrintWriter(stringWriter);
    121124        MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock();
    122125        try {
    123126            for (IPrimitive osm : sel) {
    124                 txtMappaint.append(tr("Styles Cache for \"{0}\":", osm.getDisplayName(DefaultNameFormatter.getInstance())));
     127                String heading = tr("Styles for \"{0}\":", osm.getDisplayName(DefaultNameFormatter.getInstance()));
     128                txtMappaint.println(heading);
     129                txtMappaint.println(repeatString("=", heading.length()));
    125130
    126131                MultiCascade mc = new MultiCascade();
     
    128133                for (StyleSource s : elemstyles.getStyleSources()) {
    129134                    if (s.active) {
    130                         txtMappaint.append(tr("\n\n> applying {0} style \"{1}\"\n", getSort(s), s.getDisplayString()));
     135                        heading = tr("{0} style \"{1}\"", getSort(s), s.getDisplayString());
     136                        txtMappaint.println(heading);
     137                        txtMappaint.println(repeatString("-", heading.length()));
    131138                        s.apply(mc, osm, scale, false);
    132                         txtMappaint.append(tr("\nRange:{0}", mc.range));
     139                        txtMappaint.println(tr("Display range: {0}", mc.range));
    133140                        for (Entry<String, Cascade> e : mc.getLayers()) {
    134                             txtMappaint.append("\n ").append(e.getKey()).append(": \n").append(e.getValue());
     141                            txtMappaint.println(tr("Layer {0}", e.getKey()));
     142                            txtMappaint.print(" * ");
     143                            txtMappaint.println(e.getValue());
    135144                        }
    136                     } else {
    137                         txtMappaint.append(tr("\n\n> skipping \"{0}\" (not active)", s.getDisplayString()));
    138145                    }
    139146                }
    140                 txtMappaint.append(tr("\n\nList of generated Styles:\n"));
     147                txtMappaint.println();
     148                heading = tr("List of generated Styles:");
     149                txtMappaint.println(heading);
     150                txtMappaint.println(repeatString("-", heading.length()));
    141151                StyleElementList sl = elemstyles.get(osm, scale, nc);
    142152                for (StyleElement s : sl) {
    143                     txtMappaint.append(" * ").append(s).append('\n');
     153                    txtMappaint.print(" * ");
     154                    txtMappaint.println(s);
    144155                }
    145                 txtMappaint.append("\n\n");
     156                txtMappaint.println();
     157                txtMappaint.println();
    146158            }
    147159        } finally {
     
    153165            StyleCache sc2 = selList.get(1).getCachedStyle();
    154166            if (sc1 == sc2) {
    155                 txtMappaint.append(tr("The 2 selected objects have identical style caches."));
     167                txtMappaint.println(tr("The 2 selected objects have identical style caches."));
    156168            }
    157169            if (!sc1.equals(sc2)) {
    158                 txtMappaint.append(tr("The 2 selected objects have different style caches."));
     170                txtMappaint.println(tr("The 2 selected objects have different style caches."));
    159171            }
    160172            if (sc1 != sc2 && sc1.equals(sc2)) {
    161                 txtMappaint.append(tr("Warning: The 2 selected objects have equal, but not identical style caches."));
    162             }
    163         }
    164         return txtMappaint.toString();
     173                txtMappaint.println(tr("Warning: The 2 selected objects have equal, but not identical style caches."));
     174            }
     175        }
     176        return stringWriter.toString();
     177    }
     178
     179    private static String repeatString(String string, int count) {
     180        // Java 11: use String.repeat
     181        return new String(new char[count]).replace("\0", string);
    165182    }
    166183
     
    201218    private static String getSort(StyleSource s) {
    202219        if (s instanceof MapCSSStyleSource) {
    203             return tr("mapcss");
     220            return "MapCSS";
    204221        } else {
    205             return tr("unknown");
     222            return tr("UNKNOWN");
    206223        }
    207224    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Range.java

    r14353 r16322  
    103103    @Override
    104104    public String toString() {
    105         return String.format("|s%s-%s", lower, upper);
     105        return String.format("|z%.4f-%.4f", lower, upper);
    106106    }
    107107
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialogTest.java

    r16257 r16322  
    115115        // CHECKSTYLE.OFF: LineLength
    116116        String baseText =
    117                 "Styles Cache for \"node\":\n" +
    118                 "\n" +
    119                 "> applying mapcss style \"JOSM default (MapCSS)\"\n" +
    120                 "\n" +
    121                 "Range:|s119.4328566955879-Infinity\n" +
    122                 " default: \n" +
    123                 "Cascade{ font-size:8.0; major-z-index:4.95; symbol-fill-color:#FF0000; symbol-shape:Keyword{square}; symbol-size:6.0; symbol-stroke-color:#FF0000; }\n" +
    124                 "\n" +
    125                 "> skipping \"Potlatch 2\" (not active)\n" +
     117                "Styles for \"node\":\n" +
     118                "==================\n" +
     119                "MapCSS style \"JOSM default (MapCSS)\"\n" +
     120                "------------------------------------\n" +
     121                "Display range: |z119.4329-Infinity\n" +
     122                "Layer default\n" +
     123                " * Cascade{ font-size:8.0; major-z-index:4.95; symbol-fill-color:#FF0000; symbol-shape:Keyword{square}; symbol-size:6.0; symbol-stroke-color:#FF0000; }\n" +
    126124                "\n" +
    127125                "List of generated Styles:\n" +
     126                "-------------------------\n" +
    128127                " * NodeElement{z_idx=[4.95/0.0/0.0]  symbol=[symbolShape=SQUARE size=6 stroke=java.awt.BasicStroke strokeColor=java.awt.Color[r=255,g=0,b=0] fillColor=java.awt.Color[r=255,g=0,b=0]]}\n" +
    129128                "\n" +
     
    144143            ds.addPrimitive(n);
    145144            ds.addSelected(n);
    146             assertEquals(baseText + baseText + "The 2 selected objects have identical style caches.",
     145            assertEquals(baseText + baseText + "The 2 selected objects have identical style caches.\n",
    147146                    InspectPrimitiveDialog.buildMapPaintText().replaceAll("@(\\p{XDigit})+", ""));
    148147        } finally {
Note: See TracChangeset for help on using the changeset viewer.