Ignore:
Timestamp:
2018-03-25T18:53:04+02:00 (21 months ago)
Author:
Don-vip
Message:

introduce PrimitiveRenderer to replace OsmPrimitivRenderer (now deprecated). Change NameFormatter API to support IPrimitive instead of OsmPrimitive. Enhances interfaces in consequence.

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

Legend:

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

    r13561 r13564  
    316316    public PrimitiveId getPrimitiveId() {
    317317        return new SimplePrimitiveId(getUniqueId(), getType());
    318     }
    319 
    320     /**
    321      * Gets the type this primitive is displayed at
    322      * @return A {@link OsmPrimitiveType}
    323      */
    324     public OsmPrimitiveType getDisplayType() {
    325         return getType();
    326318    }
    327319
  • trunk/src/org/openstreetmap/josm/data/osm/DefaultNameFormatter.java

    r13493 r13564  
    3434import org.openstreetmap.josm.tools.I18n;
    3535import org.openstreetmap.josm.tools.Utils;
     36import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
    3637
    3738/**
    38  * This is the default implementation of a {@link NameFormatter} for names of {@link OsmPrimitive}s
     39 * This is the default implementation of a {@link NameFormatter} for names of {@link IPrimitive}s
    3940 * and {@link HistoryOsmPrimitive}s.
    4041 * @since 12663 (moved from {@code gui} package)
     
    129130
    130131    /**
    131      * Formats a name for an {@link OsmPrimitive}.
     132     * Formats a name for an {@link IPrimitive}.
    132133     *
    133134     * @param osm the primitive
    134135     * @return the name
    135136     * @since 10991
    136      */
    137     public String format(OsmPrimitive osm) {
    138         if (osm instanceof Node) {
    139             return format((Node) osm);
    140         } else if (osm instanceof Way) {
    141             return format((Way) osm);
    142         } else if (osm instanceof Relation) {
    143             return format((Relation) osm);
     137     * @since 13564 (signature)
     138     */
     139    public String format(IPrimitive osm) {
     140        if (osm instanceof INode) {
     141            return format((INode) osm);
     142        } else if (osm instanceof IWay) {
     143            return format((IWay) osm);
     144        } else if (osm instanceof IRelation) {
     145            return format((IRelation) osm);
    144146        }
    145147        return null;
     
    147149
    148150    @Override
    149     public String format(Node node) {
     151    public String format(INode node) {
    150152        StringBuilder name = new StringBuilder();
    151153        if (node.isIncomplete()) {
     
    153155        } else {
    154156            TaggingPreset preset = TaggingPresetNameTemplateList.getInstance().findPresetTemplate(node);
    155             if (preset == null) {
     157            if (preset == null || !(node instanceof TemplateEngineDataProvider)) {
    156158                String n;
    157159                if (Config.getPref().getBoolean("osm-primitives.localize-name", true)) {
     
    184186                name.append(n);
    185187            } else {
    186                 preset.nameTemplate.appendText(name, node);
     188                preset.nameTemplate.appendText(name, (TemplateEngineDataProvider) node);
    187189            }
    188190            if (node.isLatLonKnown() && Config.getPref().getBoolean("osm-primitives.showcoor")) {
     
    204206    }
    205207
    206     private final Comparator<Node> nodeComparator = (n1, n2) -> format(n1).compareTo(format(n2));
    207 
    208     @Override
    209     public Comparator<Node> getNodeComparator() {
     208    private final Comparator<INode> nodeComparator = (n1, n2) -> format(n1).compareTo(format(n2));
     209
     210    @Override
     211    public Comparator<INode> getNodeComparator() {
    210212        return nodeComparator;
    211213    }
    212214
    213215    @Override
    214     public String format(Way way) {
     216    public String format(IWay way) {
    215217        StringBuilder name = new StringBuilder();
    216218
     
    231233        } else {
    232234            TaggingPreset preset = TaggingPresetNameTemplateList.getInstance().findPresetTemplate(way);
    233             if (preset == null) {
     235            if (preset == null || !(way instanceof TemplateEngineDataProvider)) {
    234236                String n;
    235237                if (Config.getPref().getBoolean("osm-primitives.localize-name", true)) {
     
    274276                name.append(n);
    275277            } else {
    276                 preset.nameTemplate.appendText(name, way);
     278                preset.nameTemplate.appendText(name, (TemplateEngineDataProvider) way);
    277279            }
    278280
     
    296298    }
    297299
    298     private final Comparator<Way> wayComparator = (w1, w2) -> format(w1).compareTo(format(w2));
    299 
    300     @Override
    301     public Comparator<Way> getWayComparator() {
     300    private final Comparator<IWay> wayComparator = (w1, w2) -> format(w1).compareTo(format(w2));
     301
     302    @Override
     303    public Comparator<IWay> getWayComparator() {
    302304        return wayComparator;
    303305    }
    304306
    305307    @Override
    306     public String format(Relation relation) {
     308    public String format(IRelation relation) {
    307309        StringBuilder name = new StringBuilder();
    308310        if (relation.isIncomplete()) {
     
    334336    }
    335337
    336     private static StringBuilder formatRelationNameAndType(Relation relation, StringBuilder result, TaggingPreset preset) {
    337         if (preset == null) {
     338    private static StringBuilder formatRelationNameAndType(IRelation relation, StringBuilder result, TaggingPreset preset) {
     339        if (preset == null || !(relation instanceof TemplateEngineDataProvider)) {
    338340            result.append(getRelationTypeName(relation));
    339341            String relationName = getRelationName(relation);
     
    345347            result.append(" (").append(relationName).append(", ");
    346348        } else {
    347             preset.nameTemplate.appendText(result, relation);
     349            preset.nameTemplate.appendText(result, (TemplateEngineDataProvider) relation);
    348350            result.append('(');
    349351        }
     
    351353    }
    352354
    353     private final Comparator<Relation> relationComparator = (r1, r2) -> {
     355    private final Comparator<IRelation> relationComparator = (r1, r2) -> {
    354356        //TODO This doesn't work correctly with formatHooks
    355357
     
    394396
    395397    @Override
    396     public Comparator<Relation> getRelationComparator() {
     398    public Comparator<IRelation> getRelationComparator() {
    397399        return relationComparator;
    398400    }
  • trunk/src/org/openstreetmap/josm/data/osm/INode.java

    r12161 r13564  
    2929     */
    3030    void setEastNorth(EastNorth eastNorth);
     31
     32    @Override
     33    default String getDisplayName(NameFormatter formatter) {
     34        return formatter.format(this);
     35    }
    3136}
  • trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java

    r13493 r13564  
    233233     */
    234234    String getLocalName();
     235
     236    /**
     237     * Replies the display name of a primitive formatted by <code>formatter</code>
     238     * @param formatter formatter to use
     239     *
     240     * @return the display name
     241     * @since 13564
     242     */
     243    String getDisplayName(NameFormatter formatter);
     244
     245    /**
     246     * Gets the type this primitive is displayed at
     247     * @return A {@link OsmPrimitiveType}
     248     * @since 13564
     249     */
     250    default OsmPrimitiveType getDisplayType() {
     251        return getType();
     252    }
    235253}
  • trunk/src/org/openstreetmap/josm/data/osm/IRelation.java

    r9460 r13564  
    3434     */
    3535    OsmPrimitiveType getMemberType(int idx);
     36
     37    /**
     38     * Determines if at least one child primitive is incomplete.
     39     *
     40     * @return true if at least one child primitive is incomplete
     41     * @since 13564
     42     */
     43    default boolean hasIncompleteMembers() {
     44        return false;
     45    }
     46
     47    @Override
     48    default String getDisplayName(NameFormatter formatter) {
     49        return formatter.format(this);
     50    }
    3651}
  • trunk/src/org/openstreetmap/josm/data/osm/IWay.java

    r9460 r13564  
    1616
    1717    /**
     18     * Replies the real number of nodes in this way (full number of nodes minus one if this way is closed)
     19     *
     20     * @return the real number of nodes in this way.
     21     *
     22     * @see #getNodesCount()
     23     * @see #isClosed()
     24     * @since 5847
     25     * @since 13564 (IWay)
     26     */
     27    default int getRealNodesCount() {
     28        int count = getNodesCount();
     29        return isClosed() ? count-1 : count;
     30    }
     31
     32    /**
    1833     * Returns id of the node at given index.
    1934     * @param idx node index
     
    2742     */
    2843    boolean isClosed();
     44
     45    @Override
     46    default String getDisplayName(NameFormatter formatter) {
     47        return formatter.format(this);
     48    }
    2949}
  • trunk/src/org/openstreetmap/josm/data/osm/NameFormatter.java

    r12189 r13564  
    55
    66/**
    7  * Formats a name for a {@link OsmPrimitive}.
     7 * Formats a name for an {@link IPrimitive}.
    88 * @since 1990
    99 */
     
    1111
    1212    /**
    13      * Formats a name for a {@link Node}.
     13     * Formats a name for a {@link INode}.
    1414     *
    1515     * @param node the node
    1616     * @return the name
     17     * @since 13564 (signature)
    1718     */
    18     String format(Node node);
     19    String format(INode node);
    1920
    2021    /**
    21      * Formats a name for a {@link Way}.
     22     * Formats a name for a {@link IWay}.
    2223     *
    2324     * @param way the way
    2425     * @return the name
     26     * @since 13564 (signature)
    2527     */
    26     String format(Way way);
     28    String format(IWay way);
    2729
    2830    /**
    29      * Formats a name for a {@link Relation}.
     31     * Formats a name for a {@link IRelation}.
    3032     *
    3133     * @param relation the relation
    3234     * @return the name
     35     * @since 13564 (signature)
    3336     */
    34     String format(Relation relation);
     37    String format(IRelation relation);
    3538
    3639    /**
     
    4548     * Gets a comparator that sorts the nodes by the string that this formatter would create for them
    4649     * @return That comparator
     50     * @since 13564 (signature)
    4751     */
    48     Comparator<Node> getNodeComparator();
     52    Comparator<INode> getNodeComparator();
    4953
    5054    /**
    5155     * Gets a comparator that sorts the ways by the string that this formatter would create for them
    5256     * @return That comparator
     57     * @since 13564 (signature)
    5358     */
    54     Comparator<Way> getWayComparator();
     59    Comparator<IWay> getWayComparator();
    5560
    5661    /**
    5762     * Gets a comparator that sorts the relations by the string that this formatter would create for them
    5863     * @return That comparator
     64     * @since 13564 (signature)
    5965     */
    60     Comparator<Relation> getRelationComparator();
     66    Comparator<IRelation> getRelationComparator();
    6167}
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r13173 r13564  
    317317
    318318    @Override
    319     public String getDisplayName(NameFormatter formatter) {
    320         return formatter.format(this);
    321     }
    322 
    323     @Override
    324319    public OsmPrimitiveType getType() {
    325320        return OsmPrimitiveType.NODE;
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r13453 r13564  
    13651365    }
    13661366
    1367     /**
    1368      * Replies the display name of a primitive formatted by <code>formatter</code>
    1369      * @param formatter formatter to use
    1370      *
    1371      * @return the display name
    1372      */
    1373     public abstract String getDisplayName(NameFormatter formatter);
    1374 
    13751367    @Override
    13761368    public Collection<String> getTemplateKeys() {
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r13434 r13564  
    395395    }
    396396
    397     @Override
    398     public String getDisplayName(NameFormatter formatter) {
    399         return formatter.format(this);
    400     }
    401 
    402397    /**
    403398     * Replies the set of  {@link OsmPrimitive}s referred to by at least one
     
    525520    }
    526521
    527     /**
    528      * Determines if at least one child primitive is incomplete.
    529      *
    530      * @return true if at least one child primitive is incomplete
    531      */
     522    @Override
    532523    public boolean hasIncompleteMembers() {
    533524        RelationMember[] members = this.members;
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r13512 r13564  
    105105
    106106    /**
    107      * Replies the real number of nodes in this way (full number of nodes minus one if this way is closed)
    108      *
    109      * @return the real number of nodes in this way.
    110      *
    111      * @see #getNodesCount()
    112      * @see #isClosed()
    113      * @since 5847
    114      */
    115     public int getRealNodesCount() {
    116         int count = getNodesCount();
    117         return isClosed() ? count-1 : count;
    118     }
    119 
    120     /**
    121107     * Replies the node at position <code>index</code>.
    122108     *
     
    576562        }
    577563        return false;
    578     }
    579 
    580     @Override
    581     public String getDisplayName(NameFormatter formatter) {
    582         return formatter.format(this);
    583564    }
    584565
Note: See TracChangeset for help on using the changeset viewer.