Ignore:
Timestamp:
2011-09-17T10:59:32+02:00 (13 years ago)
Author:
jttt
Message:

Custom primitive name formatters via tagging presets

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

Legend:

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

    r4150 r4431  
    1717
    1818public abstract class AbstractPrimitive implements IPrimitive {
    19    
     19
    2020    private static final AtomicLong idCounter = new AtomicLong(0);
    2121
     
    305305        }
    306306    }
    307    
     307
    308308    /**
    309309     * Marks this primitive as being modified.
     
    373373        return (flags & FLAG_VISIBLE) != 0;
    374374    }
    375    
     375
    376376    /**
    377377     * Sets whether this primitive is visible, i.e. whether it is known on the server
     
    414414        return (flags & FLAG_INCOMPLETE) != 0;
    415415    }
    416    
     416
    417417    protected String getFlagsAsString() {
    418418        StringBuilder builder = new StringBuilder();
     
    528528        }
    529529    }
    530    
     530
    531531    /**
    532532     * Remove the given key from the list
     
    589589    }
    590590
     591    public final String getIgnoreCase(String key) {
     592        String[] keys = this.keys;
     593        if (key == null)
     594            return null;
     595        if (keys == null)
     596            return null;
     597        for (int i=0; i<keys.length;i+=2) {
     598            if (keys[i].equalsIgnoreCase(key)) return keys[i+1];
     599        }
     600        return null;
     601    }
     602
    591603    @Override
    592604    public final Collection<String> keySet() {
     
    642654     */
    643655    abstract protected void keysChangedImpl(Map<String, String> originalKeys);
    644    
     656
    645657    /**
    646658     * Replies the name of this primitive. The default implementation replies the value
     
    680692        return getName();
    681693    }
    682    
    683     /**
    684      * Replies the display name of a primitive formatted by <code>formatter</code>
    685      *
    686      * @return the display name
    687      */
    688     @Override
    689     public abstract String getDisplayName(NameFormatter formatter);
    690694
    691695}
  • trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java

    r4100 r4431  
    3030    int getChangesetId();
    3131    void setChangesetId(int changesetId);
    32    
     32
    3333    void visit(PrimitiveVisitor visitor);
    3434    String getName();
    3535    String getLocalName();
    36     String getDisplayName(NameFormatter formatter);
    3736
    3837}
  • trunk/src/org/openstreetmap/josm/data/osm/NameFormatter.java

    r4100 r4431  
    55
    66public interface NameFormatter {
    7     String format(INode node);
    8     String format(IWay way);
    9     String format(IRelation relation);
     7    String format(Node node);
     8    String format(Way way);
     9    String format(Relation relation);
    1010    String format(Changeset changeset);
    1111
  • trunk/src/org/openstreetmap/josm/data/osm/NodeData.java

    r4126 r4431  
    2525        return lat != Double.NaN && lon != Double.NaN;
    2626    }
    27    
     27
    2828    @Override
    2929    public LatLon getCoor() {
     
    7777    }
    7878
    79     @Override
    80     public String getDisplayName(NameFormatter formatter) {
    81         return formatter.format(this);
    82     }
    8379}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r4103 r4431  
    2525import org.openstreetmap.josm.tools.CheckParameterUtil;
    2626import org.openstreetmap.josm.tools.Predicate;
     27import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
    2728
    2829/**
     
    3637 * @author imi
    3738 */
    38 abstract public class OsmPrimitive extends AbstractPrimitive implements Comparable<OsmPrimitive> {
     39abstract public class OsmPrimitive extends AbstractPrimitive implements Comparable<OsmPrimitive>, TemplateEngineDataProvider {
     40    private static final String SPECIAL_VALUE_ID = "id";
     41    private static final String SPECIAL_VALUE_LOCAL_NAME = "localname";
     42
    3943
    4044    /**
     
    412416        super.updateFlags(flag, value);
    413417    }
    414    
     418
    415419    @Override
    416420    protected final void updateFlags(int flag, boolean value) {
     
    621625
    622626        String directionDefault = "oneway? | incline=* | aerialway=* | "+
    623         "waterway=stream | waterway=river | waterway=canal | waterway=drain | waterway=rapids | "+
    624         "\"piste:type\"=downhill | \"piste:type\"=sled | man_made=\"piste:halfpipe\" | "+
    625         "junction=roundabout";
     627                "waterway=stream | waterway=river | waterway=canal | waterway=drain | waterway=rapids | "+
     628                "\"piste:type\"=downhill | \"piste:type\"=sled | man_made=\"piste:halfpipe\" | "+
     629                "junction=roundabout";
    626630
    627631        try {
     
    700704     * Keys handling
    701705     ------------*/
    702    
     706
    703707    @Override
    704708    public final void setKeys(Map<String, String> keys) {
     
    710714        }
    711715    }
    712    
     716
    713717    @Override
    714718    public final void put(String key, String value) {
     
    719723            writeUnlock(locked);
    720724        }
    721     } 
    722    
     725    }
     726
    723727    @Override
    724728    public final void remove(String key) {
     
    739743            writeUnlock(locked);
    740744        }
    741     } 
    742    
     745    }
     746
    743747    @Override
    744748    protected final void keysChangedImpl(Map<String, String> originalKeys) {
     
    857861    /**
    858862     * <p>Visits {@code visitor} for all referrers.</p>
    859      * 
     863     *
    860864     * @param visitor the visitor. Ignored, if null.
    861865     */
     
    889893        if (referrers == null) return false;
    890894        checkDataset();
    891         if (referrers instanceof OsmPrimitive) {
    892           return n<=1 && referrers instanceof Way && ((OsmPrimitive)referrers).dataSet == dataSet;
    893         } else {
    894           int counter=0;
    895           for (OsmPrimitive o : (OsmPrimitive[])referrers) {
    896             if (dataSet == o.dataSet && o instanceof Way) {
    897               if (++counter >= n)
    898                 return true;
    899             }
    900           }
    901           return false;
     895        if (referrers instanceof OsmPrimitive)
     896            return n<=1 && referrers instanceof Way && ((OsmPrimitive)referrers).dataSet == dataSet;
     897        else {
     898            int counter=0;
     899            for (OsmPrimitive o : (OsmPrimitive[])referrers) {
     900                if (dataSet == o.dataSet && o instanceof Way) {
     901                    if (++counter >= n)
     902                        return true;
     903                }
     904            }
     905            return false;
    902906        }
    903907    }
     
    10021006
    10031007        return
    1004         isDeleted() == other.isDeleted()
    1005         && isModified() == other.isModified()
    1006         && timestamp == other.timestamp
    1007         && version == other.version
    1008         && isVisible() == other.isVisible()
    1009         && (user == null ? other.user==null : user==other.user)
    1010         && changesetId == other.changesetId;
     1008                isDeleted() == other.isDeleted()
     1009                && isModified() == other.isModified()
     1010                && timestamp == other.timestamp
     1011                && version == other.version
     1012                && isVisible() == other.isVisible()
     1013                && (user == null ? other.user==null : user==other.user)
     1014                && changesetId == other.changesetId;
    10111015    }
    10121016
     
    11011105    }
    11021106
     1107    /**
     1108     * Replies the display name of a primitive formatted by <code>formatter</code>
     1109     *
     1110     * @return the display name
     1111     */
     1112    public abstract String getDisplayName(NameFormatter formatter);
     1113
     1114    @Override
     1115    public Collection<String> getTemplateKeys() {
     1116        Collection<String> keySet = keySet();
     1117        List<String> result = new ArrayList<String>(keySet.size() + 2);
     1118        result.add(SPECIAL_VALUE_ID);
     1119        result.add(SPECIAL_VALUE_LOCAL_NAME);
     1120        result.addAll(keySet);
     1121        return result;
     1122    }
     1123
     1124    @Override
     1125    public Object getTemplateValue(String name, boolean special) {
     1126        if (special) {
     1127            String lc = name.toLowerCase();
     1128            if (SPECIAL_VALUE_ID.equals(lc))
     1129                return getId();
     1130            else if (SPECIAL_VALUE_LOCAL_NAME.equals(lc))
     1131                return getLocalName();
     1132            else
     1133                return null;
     1134
     1135        } else
     1136            return getIgnoreCase(name);
     1137    }
     1138
     1139    @Override
     1140    public boolean evaluateCondition(Match condition) {
     1141        return condition.match(this);
     1142    }
     1143
    11031144}
  • trunk/src/org/openstreetmap/josm/data/osm/RelationData.java

    r4100 r4431  
    6262        return OsmPrimitiveType.RELATION;
    6363    }
    64    
    65     @Override 
     64
     65    @Override
    6666    public void visit(PrimitiveVisitor visitor) {
    6767        visitor.visit(this);
    6868    }
    6969
    70     @Override
    71     public String getDisplayName(NameFormatter formatter) {
    72         return formatter.format(this);
    73     }
    74 
    7570}
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r4321 r4431  
    162162        visitor.visit(this);
    163163    }
    164    
     164
    165165    @Override public void visit(PrimitiveVisitor visitor) {
    166166        visitor.visit(this);
     
    453453
    454454
    455     @Override
    456455    public String getDisplayName(NameFormatter formatter) {
    457456        return formatter.format(this);
  • trunk/src/org/openstreetmap/josm/data/osm/WayData.java

    r4100 r4431  
    44import java.util.ArrayList;
    55import java.util.List;
     6
    67import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
    78
     
    5758        return OsmPrimitiveType.WAY;
    5859    }
    59    
    60     @Override 
     60
     61    @Override
    6162    public void visit(PrimitiveVisitor visitor) {
    6263        visitor.visit(this);
    6364    }
    6465
    65     @Override
    66     public String getDisplayName(NameFormatter formatter) {
    67         return formatter.format(this);
    68     }
    69 
    7066}
Note: See TracChangeset for help on using the changeset viewer.