Changeset 9400 in josm


Ignore:
Timestamp:
2016-01-11T01:02:56+01:00 (8 years ago)
Author:
Don-vip
Message:

see #12282 - detect missing icons for MapCSS styles

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r9334 r9400  
    8383
    8484    /**
    85      * IconReference is used to remember the associated style source for
    86      * each icon URL.
     85     * IconReference is used to remember the associated style source for each icon URL.
    8786     * This is necessary because image URLs can be paths relative
    88      * to the source file and we have cascading of properties from different
    89      * source files.
     87     * to the source file and we have cascading of properties from different source files.
    9088     */
    9189    public static class IconReference {
     
    106104
    107105    /**
    108      * Image provider for icon. Note that this is a provider only. A @link{ImageProvider#get()} call may still
    109      * fail!
     106     * Image provider for icon. Note that this is a provider only. A @link{ImageProvider#get()} call may still fail!
    110107     *
    111108     * @param ref reference to the requested icon
     
    124121                .setOptional(true);
    125122        if (test && i.get() == null) {
    126             Main.warn("Mappaint style \""+namespace+"\" ("+ref.source.getDisplayString()+") icon \"" + ref.iconName + "\" not found.");
     123            String msg = "Mappaint style \""+namespace+"\" ("+ref.source.getDisplayString()+") icon \"" + ref.iconName + "\" not found.";
     124            ref.source.logWarning(msg);
     125            Main.warn(msg);
    127126            return null;
    128127        }
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTest.java

    r9334 r9400  
    1414import org.openstreetmap.josm.JOSMFixture;
    1515import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
     16import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
     17import org.openstreetmap.josm.gui.mappaint.StyleKeys;
    1618import org.openstreetmap.josm.gui.mappaint.StyleSource;
     19import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
     20import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.AssignmentInstruction;
     21import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
     22import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    1723import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
    1824import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
     
    4854                System.out.println(source.url);
    4955                StyleSource style = MapPaintStyles.addStyle(source);
     56                if (style instanceof MapCSSStyleSource) {
     57                    // Force loading of all icons to detect missing ones
     58                    for (MapCSSRule rule : ((MapCSSStyleSource) style).rules) {
     59                        for (Instruction instruction : rule.declaration.instructions) {
     60                            if (instruction instanceof AssignmentInstruction) {
     61                                AssignmentInstruction ai = (AssignmentInstruction) instruction;
     62                                if (StyleKeys.ICON_IMAGE.equals(ai.key)
     63                                 || StyleKeys.FILL_IMAGE.equals(ai.key)
     64                                 || StyleKeys.REPEAT_IMAGE.equals(ai.key)) {
     65                                    if (ai.val instanceof String) {
     66                                        MapPaintStyles.getIconProvider(new IconReference((String) ai.val, style), true);
     67                                    }
     68                                }
     69                            }
     70                        }
     71                    }
     72                }
    5073                System.out.println(style.isValid() ? " => OK" : " => KO");
    5174                Collection<Throwable> errors = style.getErrors();
Note: See TracChangeset for help on using the changeset viewer.