Changeset 9473 in josm


Ignore:
Timestamp:
2016-01-15T22:25:06+01:00 (8 years ago)
Author:
simon04
Message:

fix #12343 - Display at most 20 primitives for some confirmation dialogs (e.g., deletion of relations)

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r9062 r9473  
    225225                            tr("Cannot merge nodes: Would have to delete way {0} which is still used by {1}",
    226226                                DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(w),
    227                                 DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(w.getReferrers())),
     227                                DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(w.getReferrers(), 20)),
    228228                            tr("Warning"),
    229229                            JOptionPane.WARNING_MESSAGE,
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r9371 r9473  
    505505                + "<br/>"
    506506                + "Do you really want to delete?",
    507                 relations.size(), relations.size(), DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(relations))
     507                relations.size(), relations.size(), DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(relations, 20))
    508508                + "</html>"));
    509509        return ConditionalOptionPaneUtil.showConfirmationDialog(
  • trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java

    r9203 r9473  
    644644     * Formats the given collection of primitives as an HTML unordered list.
    645645     * @param primitives collection of primitives to format
     646     * @param maxElements the maximum number of elements to display
    646647     * @return HTML unordered list
    647648     */
    648     public String formatAsHtmlUnorderedList(Collection<? extends OsmPrimitive> primitives) {
    649         return Utils.joinAsHtmlUnorderedList(Utils.transform(primitives, new Function<OsmPrimitive, String>() {
     649    public String formatAsHtmlUnorderedList(Collection<? extends OsmPrimitive> primitives, int maxElements) {
     650        final Collection<String> displayNames = Utils.transform(primitives, new Function<OsmPrimitive, String>() {
    650651
    651652            @Override
     
    653654                return x.getDisplayName(DefaultNameFormatter.this);
    654655            }
    655         }));
    656     }
    657 
    658     /**
    659      * Formats the given primitive(s) as an HTML unordered list.
    660      * @param primitives primitive(s) to format
     656        });
     657        return Utils.joinAsHtmlUnorderedList(Utils.limit(displayNames, maxElements, "..."));
     658    }
     659
     660    /**
     661     * Formats the given primitive as an HTML unordered list.
     662     * @param primitive primitive to format
    661663     * @return HTML unordered list
    662664     */
    663     public String formatAsHtmlUnorderedList(OsmPrimitive... primitives) {
    664         return formatAsHtmlUnorderedList(Arrays.asList(primitives));
     665    public String formatAsHtmlUnorderedList(OsmPrimitive primitive) {
     666        return formatAsHtmlUnorderedList(Collections.singletonList(primitive), 1);
    665667    }
    666668}
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java

    r9211 r9473  
    551551                + "Do you want to continue?",
    552552                parentRelations.size(), parentRelations.size(), primitives.size(),
    553                 DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(parentRelations));
     553                DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(parentRelations, 20));
    554554
    555555        if (!ConditionalOptionPaneUtil.showConfirmationDialog(
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r9419 r9473  
    13071307            return null;
    13081308        } else {
    1309             final List<String> lines = Arrays.asList(s.split("\\n"));
    1310             if (lines.size() > maxLines) {
    1311                 return join("\n", lines.subList(0, maxLines - 1)) + "\n...";
     1309            return join("\n", limit(Arrays.asList(s.split("\\n")), maxLines, "..."));
     1310        }
     1311    }
     1312
     1313    /**
     1314     * If the collection {@code elements} is larger than {@code maxElements} elements,
     1315     * the collection is shortened and the {@code overflowIndicator} is appended.
     1316     * @param elements collection to shorten
     1317     * @param maxElements maximum number of elements to keep (including including the {@code overflowIndicator})
     1318     * @param overflowIndicator the element used to indicate that the collection has been shortened
     1319     * @return the shortened collection
     1320     */
     1321    public static <T> Collection<T> limit(Collection<T> elements, int maxElements, T overflowIndicator) {
     1322        if (elements == null) {
     1323            return null;
     1324        } else {
     1325            if (elements.size() > maxElements) {
     1326                final Collection<T> r = new ArrayList<>(maxElements);
     1327                final Iterator<T> it = elements.iterator();
     1328                while (r.size() < maxElements - 1) {
     1329                    r.add(it.next());
     1330                }
     1331                r.add(overflowIndicator);
     1332                return r;
    13121333            } else {
    1313                 return s;
     1334                return elements;
    13141335            }
    13151336        }
Note: See TracChangeset for help on using the changeset viewer.