Changeset 2460 in josm for trunk


Ignore:
Timestamp:
2009-11-15T15:28:15+01:00 (14 years ago)
Author:
stoecker
Message:

cleanup of mappaint error text handling

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2452 r2460  
    874874
    875875
    876     // TODO Should be part of validator
    877     // This used to be OsmPrimitive.errors. I don't really like that such information is kept here,
    878     // but at least it's not such memory waste as having it in (every) OsmPrimitive
     876    // TODO Should be completely part of validator
    879877    private Map<OsmPrimitive, List<String>> errors = new HashMap<OsmPrimitive, List<String>>();
    880878
    881     void setErrors(OsmPrimitive primitive, List<String> errors) {
    882         if (errors != null && !errors.isEmpty()) {
    883             this.errors.put(primitive, errors);
    884         } else {
    885             this.errors.remove(primitive);
    886         }
     879    public void addError(OsmPrimitive primitive, String error) {
     880        List<String> perrors = errors.get(primitive);
     881        if (perrors == null) {
     882            perrors = new ArrayList<String>();
     883        }
     884        perrors.add(error);
     885        errors.put(primitive, perrors);
    887886    }
    888887
     
    890889        return errors.get(primitive);
    891890    }
     891
     892    public void clearErrors()
     893    {
     894        errors.clear();
     895    }
    892896}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2459 r2460  
    9999    public Integer mappaintDrawnCode = 0;
    100100
    101     public void putError(String text, boolean isError)
    102     {
    103         checkDataset();
    104         List<String> errors = dataSet.getErrors(this);
    105         if (errors == null) {
    106             errors = new ArrayList<String>();
    107         }
    108         String s = isError ? tr("Error: {0}", text) : tr("Warning: {0}", text);
    109         errors.add(s);
    110         dataSet.setErrors(this, errors);
    111     }
    112     public void clearErrors()
    113     {
    114         if (dataSet != null) {
    115             dataSet.setErrors(this, null);
    116         }
    117     }
    118 
    119     public List<String> getErrors() {
    120         if (dataSet == null)
    121             return null;
    122         else
    123             return dataSet.getErrors(this);
    124     }
    125101    /* This should not be called from outside. Fixing the UI to add relevant
    126102       get/set functions calling this implicitely is preferred, so we can have
     
    154130
    155131    /**
    156      * 
     132     *
    157133     * @return DataSet this primitive is part of.
    158134     */
     
    736712     * Find primitives that reference this primitive. Returns only primitives that are included in the same
    737713     * dataset as this primitive. <br>
    738      * 
     714     *
    739715     * For example following code will add wnew as referer to all nodes of existingWay, but this method will
    740716     * not return wnew because it's not part of the dataset <br>
    741      * 
     717     *
    742718     * <code>Way wnew = new Way(existingWay)</code>
    743      * 
     719     *
    744720     * @return a collection of all primitives that reference this primitive.
    745721     */
     
    809785    /**
    810786     * Merges the technical and semantical attributes from <code>other</code> onto this.
    811      * 
     787     *
    812788     * Both this and other must be new, or both must be assigned an OSM ID. If both this and <code>other</code>
    813789     * have an assigend OSM id, the IDs have to be the same.
    814      * 
     790     *
    815791     * @param other the other primitive. Must not be null.
    816792     * @throws IllegalArgumentException thrown if other is null.
     
    10321008    /**
    10331009     * Replies the unique primitive id for this primitive
    1034      * 
     1010     *
    10351011     * @return the unique primitive id for this primitive
    10361012     */
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r2452 r2460  
    217217            return;
    218218
    219         if(fillAreas > dist) {
    220             w.clearErrors();
    221         }
    222 
    223219        if(wayStyle==null)
    224220        {
     
    246242                drawArea(w, data.isSelected(w) ? selectedColor : areaStyle.color);
    247243                if(!w.isClosed()) {
    248                     w.putError(tr("Area style way is not closed."), true);
     244                    putError(w, tr("Area style way is not closed."), true);
    249245                }
    250246            }
     
    479475                if(errs != null)
    480476                {
    481                     errs.putError(tr("multipolygon way ''{0}'' is not closed.",
     477                    putError(errs, tr("multipolygon way ''{0}'' is not closed.",
    482478                            w.getDisplayName(DefaultNameFormatter.getInstance())), true);
    483479                }
     
    556552        //    System.out.println("Restriction: " + r.keys.get("name") + " restriction " + r.keys.get("restriction"));
    557553
    558         r.clearErrors();
    559 
    560554        Way fromWay = null;
    561555        Way toWay = null;
     
    569563
    570564            if (m.getMember().isDeleted()) {
    571                 r.putError(tr("Deleted member ''{0}'' in relation.",
     565                putError(r, tr("Deleted member ''{0}'' in relation.",
    572566                        m.getMember().getDisplayName(DefaultNameFormatter.getInstance())), true);
    573567            } else if(m.getMember().incomplete)
     
    580574                    if(w.getNodesCount() < 2)
    581575                    {
    582                         r.putError(tr("Way ''{0}'' with less than two points.",
     576                        putError(r, tr("Way ''{0}'' with less than two points.",
    583577                                w.getDisplayName(DefaultNameFormatter.getInstance())), true);
    584578                    }
    585579                    else if("from".equals(m.getRole())) {
    586580                        if(fromWay != null) {
    587                             r.putError(tr("More than one \"from\" way found."), true);
     581                            putError(r, tr("More than one \"from\" way found."), true);
    588582                        } else {
    589583                            fromWay = w;
     
    591585                    } else if("to".equals(m.getRole())) {
    592586                        if(toWay != null) {
    593                             r.putError(tr("More than one \"to\" way found."), true);
     587                            putError(r, tr("More than one \"to\" way found."), true);
    594588                        } else {
    595589                            toWay = w;
     
    597591                    } else if("via".equals(m.getRole())) {
    598592                        if(via != null) {
    599                             r.putError(tr("More than one \"via\" found."), true);
     593                            putError(r, tr("More than one \"via\" found."), true);
    600594                        } else {
    601595                            via = w;
    602596                        }
    603597                    } else {
    604                         r.putError(tr("Unknown role ''{0}''.", m.getRole()), true);
     598                        putError(r, tr("Unknown role ''{0}''.", m.getRole()), true);
    605599                    }
    606600                }
     
    611605                    {
    612606                        if(via != null) {
    613                             r.putError(tr("More than one \"via\" found."), true);
     607                            putError(r, tr("More than one \"via\" found."), true);
    614608                        } else {
    615609                            via = n;
    616610                        }
    617611                    } else {
    618                         r.putError(tr("Unknown role ''{0}''.", m.getRole()), true);
     612                        putError(r, tr("Unknown role ''{0}''.", m.getRole()), true);
    619613                    }
    620614                } else {
    621                     r.putError(tr("Unknown member type for ''{0}''.", m.getMember().getDisplayName(DefaultNameFormatter.getInstance())), true);
     615                    putError(r, tr("Unknown member type for ''{0}''.", m.getMember().getDisplayName(DefaultNameFormatter.getInstance())), true);
    622616                }
    623617            }
     
    625619
    626620        if (fromWay == null) {
    627             r.putError(tr("No \"from\" way found."), true);
     621            putError(r, tr("No \"from\" way found."), true);
    628622            return;
    629623        }
    630624        if (toWay == null) {
    631             r.putError(tr("No \"to\" way found."), true);
     625            putError(r, tr("No \"to\" way found."), true);
    632626            return;
    633627        }
    634628        if (via == null) {
    635             r.putError(tr("No \"via\" node or way found."), true);
     629            putError(r, tr("No \"via\" node or way found."), true);
    636630            return;
    637631        }
     
    642636            viaNode = (Node) via;
    643637            if(!fromWay.isFirstLastNode(viaNode)) {
    644                 r.putError(tr("The \"from\" way doesn't start or end at a \"via\" node."), true);
     638                putError(r, tr("The \"from\" way doesn't start or end at a \"via\" node."), true);
    645639                return;
    646640            }
    647641            if(!toWay.isFirstLastNode(viaNode)) {
    648                 r.putError(tr("The \"to\" way doesn't start or end at a \"via\" node."), true);
     642                putError(r, tr("The \"to\" way doesn't start or end at a \"via\" node."), true);
    649643            }
    650644        }
     
    673667                viaNode = lastNode;
    674668            } else {
    675                 r.putError(tr("The \"from\" way doesn't start or end at the \"via\" way."), true);
     669                putError(r, tr("The \"from\" way doesn't start or end at the \"via\" way."), true);
    676670                return;
    677671            }
    678672            if(!toWay.isFirstLastNode(viaNode == firstNode ? lastNode : firstNode)) {
    679                 r.putError(tr("The \"to\" way doesn't start or end at the \"via\" way."), true);
     673                putError(r, tr("The \"to\" way doesn't start or end at the \"via\" way."), true);
    680674            }
    681675        }
     
    800794
    801795        if (nodeStyle == null) {
    802             r.putError(tr("Style for restriction {0} not found.", r.get("restriction")), true);
     796            putError(r, tr("Style for restriction {0} not found.", r.get("restriction")), true);
    803797            return;
    804798        }
     
    894888                if(c > 1 && pdOuter.way != null && pdOuter.way.isClosed())
    895889                {
    896                     r.putError(tr("Intersection between ways ''{0}'' and ''{1}''.",
     890                    putError(r, tr("Intersection between ways ''{0}'' and ''{1}''.",
    897891                            pdOuter.way.getDisplayName(DefaultNameFormatter.getInstance()), wInner.getDisplayName(DefaultNameFormatter.getInstance())), true);
    898892                }
     
    906900            if(!incomplete)
    907901            {
    908                 r.putError(tr("Inner way ''{0}'' is outside.",
     902                putError(r, tr("Inner way ''{0}'' is outside.",
    909903                        wInner.getDisplayName(DefaultNameFormatter.getInstance())), true);
    910904            }
     
    922916        Boolean drawn = false;
    923917
    924         r.clearErrors();
    925 
    926918        for (RelationMember m : r.getMembers())
    927919        {
    928920            if (m.getMember().isDeleted()) {
    929                 r.putError(tr("Deleted member ''{0}'' in relation.",
     921                putError(r, tr("Deleted member ''{0}'' in relation.",
    930922                        m.getMember().getDisplayName(DefaultNameFormatter.getInstance())), true);
    931923            } else if(m.getMember().incomplete) {
     
    935927                    Way w = m.getWay();
    936928                    if(w.getNodesCount() < 2) {
    937                         r.putError(tr("Way ''{0}'' with less than two points.",
     929                        putError(r, tr("Way ''{0}'' with less than two points.",
    938930                                w.getDisplayName(DefaultNameFormatter.getInstance())), true);
    939931                    }
     
    943935                        outer.add(w);
    944936                    } else {
    945                         r.putError(tr("No useful role ''{0}'' for Way ''{1}''.",
     937                        putError(r, tr("No useful role ''{0}'' for Way ''{1}''.",
    946938                                m.getRole(), w.getDisplayName(DefaultNameFormatter.getInstance())), true);
    947939                        if(!m.hasRole()) {
     
    955947                else
    956948                {
    957                     r.putError(tr("Non-Way ''{0}'' in multipolygon.",
     949                    putError(r, tr("Non-Way ''{0}'' in multipolygon.",
    958950                            m.getMember().getDisplayName(DefaultNameFormatter.getInstance())), true);
    959951                }
     
    999991            if(outerclosed.size() == 0 && outerjoin.size() == 0)
    1000992            {
    1001                 r.putError(tr("No outer way for multipolygon ''{0}''.",
     993                putError(r, tr("No outer way for multipolygon ''{0}''.",
    1002994                        r.getDisplayName(DefaultNameFormatter.getInstance())), true);
    1003995                visible = true; /* prevent killing remaining ways */
     
    10591051                    if(wayStyle.equals(innerStyle))
    10601052                    {
    1061                         r.putError(tr("Style for inner way ''{0}'' equals multipolygon.",
     1053                        putError(r, tr("Style for inner way ''{0}'' equals multipolygon.",
    10621054                                wInner.getDisplayName(DefaultNameFormatter.getInstance())), false);
    10631055                        if(!data.isSelected(r)) {
     
    10891081                            && !wayStyle.equals(outerStyle))
    10901082                    {
    1091                         r.putError(tr("Style for outer way ''{0}'' mismatches.",
     1083                        putError(r, tr("Style for outer way ''{0}'' mismatches.",
    10921084                                wOuter.getDisplayName(DefaultNameFormatter.getInstance())), true);
    10931085                    }
     
    14641456        maxEN = nc.getEastNorth(nc.getWidth() - 1, 0);
    14651457
     1458        data.clearErrors();
    14661459
    14671460        ++paintid;
     
    16451638        drawOrderNumber(p1, p2, orderNumber);
    16461639    }
     1640
     1641    public void putError(OsmPrimitive p, String text, boolean isError)
     1642    {
     1643        data.addError(p, isError ? tr("Error: {0}", text) : tr("Warning: {0}", text));
     1644    }
    16471645}
Note: See TracChangeset for help on using the changeset viewer.