Ignore:
Timestamp:
2008-08-07T10:03:52+02:00 (16 years ago)
Author:
stoecker
Message:

better sorting of selected elements and relation list, reenabled relation search, translation cleanups

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

Legend:

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

    r753 r755  
    88import java.util.Collection;
    99import java.util.Collections;
     10import java.util.Comparator;
    1011import java.util.HashSet;
     12import java.util.HashMap;
    1113import java.util.LinkedList;
    1214import java.util.List;
     
    7880                for (OsmPrimitive osm : allPrimitives())
    7981                        if (!osm.deleted)
     82                                o.add(osm);
     83                return o;
     84        }
     85
     86        public Collection<OsmPrimitive> allNonDeletedCompletePrimitives() {
     87                Collection<OsmPrimitive> o = new LinkedList<OsmPrimitive>();
     88                for (OsmPrimitive osm : allPrimitives())
     89                        if (!osm.deleted && !osm.incomplete)
    8090                                o.add(osm);
    8191                return o;
     
    230240               
    231241        }
     242
     243        // Search für Relation wieder erlauben.
     244        public static OsmPrimitive[] sort(Collection<? extends OsmPrimitive> list) {
     245                OsmPrimitive[] selArr = new OsmPrimitive[list.size()];
     246                final HashMap<Object, String> h = new HashMap<Object, String>();
     247                selArr = list.toArray(selArr);
     248                Arrays.sort(selArr, new Comparator<OsmPrimitive>() {
     249                        public int compare(OsmPrimitive a, OsmPrimitive b)
     250                        {
     251                                if(a.getClass() == b.getClass())
     252                                {
     253                                        String as = h.get(a);
     254                                        if(as == null)
     255                                        {
     256                                                as = a.getName();
     257                                                h.put(a, as);
     258                                        }
     259                                        String bs = h.get(b);
     260                                        if(bs == null)
     261                                        {
     262                                                bs = b.getName();
     263                                                h.put(b, bs);
     264                                        }
     265                                        int res = as.compareTo(bs);
     266                                        if(res != 0)
     267                                                return res;
     268                                }
     269                                return a.compareTo(b);
     270                        }
     271                });
     272                return selArr;
     273        }
    232274}
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r643 r755  
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others
    22package org.openstreetmap.josm.data.osm;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
     6
     7import java.text.DecimalFormat;
     8import java.text.NumberFormat;
    39
    410import org.openstreetmap.josm.Main;
     
    6773        public int compareTo(OsmPrimitive o) {
    6874            return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1;
    69     }
     75        }
     76
     77        public String getName() {
     78                String name;
     79                if (incomplete) {
     80                        name = tr("incomplete");
     81                } else {
     82                        NumberFormat latLonFormat = new DecimalFormat("###0.0000000");
     83
     84                        name = get("name");
     85                        if (name == null)
     86                                name = id == 0 ? "" : ""+id;
     87                        name += " ("+latLonFormat.format(coor.lat())+", "+latLonFormat.format(coor.lon())+")";
     88                }
     89                return name;
     90        }
    7091}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r655 r755  
    217217                checkTagged();
    218218                checkDirectionTagged();
     219        }
     220
     221        public String getName() {
     222                return null;
    219223        }
    220224
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r627 r755  
    11package org.openstreetmap.josm.data.osm;
     2
     3import static org.openstreetmap.josm.tools.I18n.tr;
     4import static org.openstreetmap.josm.tools.I18n.trn;
    25
    36import java.util.ArrayList;
     
    6669        public int compareTo(OsmPrimitive o) {
    6770            return o instanceof Relation ? Long.valueOf(id).compareTo(o.id) : -1;
    68     }
    69        
     71        }
     72
     73        public String getName() {
     74                String name;
     75                if (incomplete) {
     76                        name = tr("incomplete");
     77                } else {
     78                        name = get("type");
     79                        // FIXME add names of members
     80                        if (name == null)
     81                                name = tr("relation");
     82                       
     83                        name += " (";
     84                        String nameTag = get("name");
     85                        if (nameTag == null) nameTag = get("ref");
     86                        if (nameTag != null) name += "\"" + nameTag + "\", ";
     87                        int mbno = members.size();
     88                        name += trn("{0} member", "{0} members", mbno, mbno) + ")";
     89                }
     90                return name;
     91        }
     92
    7093        public boolean isIncomplete() {
    7194                for (RelationMember m : members)
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r627 r755  
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others
    22package org.openstreetmap.josm.data.osm;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
     6
     7import java.util.HashSet;
    38
    49import java.util.ArrayList;
     
    8792
    8893        public int compareTo(OsmPrimitive o) {
    89             return o instanceof Way ? Long.valueOf(id).compareTo(o.id) : -1;
    90     }
     94                if(o instanceof Relation)
     95                        return 1;
     96                return o instanceof Way ? Long.valueOf(id).compareTo(o.id) : -1;
     97        }
     98
     99        public String getName() {
     100                String name;
     101                if (incomplete) {
     102                        name = tr("incomplete");
     103                } else {
     104                        name = get("name");
     105                        if (name == null) name = get("ref");
     106                        if (name == null) {
     107                                name =
     108                                        (get("highway") != null) ? tr("highway") :
     109                                        (get("railway") != null) ? tr("railway") :
     110                                        (get("waterway") != null) ? tr("waterway") :
     111                                        (get("landuse") != null) ? tr("landuse") : "";
     112                        }
     113
     114                        int nodesNo = new HashSet<Node>(nodes).size();
     115                        name += trn(" ({0} node)", " ({0} nodes)", nodesNo, nodesNo);
     116                }
     117                return name;
     118        }
    91119
    92120        @Deprecated
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java

    r627 r755  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55import static org.openstreetmap.josm.tools.I18n.trn;
    6 
    7 import java.text.DecimalFormat;
    8 import java.text.NumberFormat;
    9 import java.util.HashSet;
    106
    117import javax.swing.Icon;
     
    3026         */
    3127        public String className;
     28        public String classNamePlural;
    3229        /**
    3330         * The name of this item.
     
    3936        public Icon icon;
    4037       
    41         /**
    42          * For formatting lat/lon
    43          */
    44         public static NumberFormat latLonFormat = new DecimalFormat("###0.0000000");
    45        
    4638        /**
    4739         * If the node has a name-key or id-key, this is displayed. If not, (lat,lon)
     
    4941         */
    5042        public void visit(Node n) {
    51                 if (n.incomplete) {
    52                         name = tr("incomplete");
    53                 } else {
    54                         name = n.get("name");
    55                         if (name == null) {
    56                                 name = n.id == 0 ? "" : ""+n.id;
    57                         }
    58                         name += " ("+latLonFormat.format(n.coor.lat())+", "+latLonFormat.format(n.coor.lon())+")";
    59                 }
     43                name = n.getName();
    6044                addId(n);
    6145                icon = ImageProvider.get("data", "node");
    62                 trn("node", "nodes", 0); // no marktrn available
    6346                className = "node";
     47                classNamePlural = trn("node", "nodes", 2);
    6448        }
    6549
     
    6953         */
    7054        public void visit(Way w) {
    71                 if (w.incomplete) {
    72                         name = tr("incomplete");
    73                 } else {
    74                         name = w.get("name");
    75                         if (name == null) name = w.get("ref");
    76                         if (name == null) {
    77                                 name =
    78                                         (w.get("highway") != null) ? "highway" :
    79                                         (w.get("railway") != null) ? "railway" :
    80                                         (w.get("waterway") != null) ? "waterway" : "";
    81                         }
    82 
    83                         int nodesNo = new HashSet<Node>(w.nodes).size();
    84                         name += trn(" ({0} node)", " ({0} nodes)", nodesNo, nodesNo);
    85                 }
     55                name = w.getName();
    8656                addId(w);
    8757                icon = ImageProvider.get("data", "way");
    88                 trn("way", "ways", 0); // no marktrn available
    8958                className = "way";
     59                classNamePlural = trn("way", "ways", 2);
    9060        }
    9161       
     
    9363         */
    9464        public void visit(Relation e) {
    95                 if (e.incomplete) {
    96                         name = tr("incomplete");
    97                 } else {
    98                         name = e.get("type");
    99                         // FIXME add names of members
    100                         if (name == null)
    101                                 name = "relation";
    102                        
    103                         name += " (";
    104                         String nameTag = e.get("name");
    105                         if (nameTag == null) nameTag = e.get("ref");
    106                         if (nameTag != null) name += "\"" + nameTag + "\", ";
    107                         int mbno = e.members.size();
    108                         name += trn("{0} member", "{0} members", mbno, mbno) + ")";
    109                 }
     65                name = e.getName();
    11066                addId(e);
    11167                icon = ImageProvider.get("data", "relation");
    112                 trn("relation", "relations", 0); // no marktrn available
    11368                className = "relation";
     69                classNamePlural = trn("relation", "relations", 2);
    11470        }
    11571       
     
    12177        private void addId(OsmPrimitive osm) {
    12278            if (Main.pref.getBoolean("osm-primitives.showid"))
    123                         name += " (id: "+osm.id+")";
     79                        name += tr(" (id: {0}))", osm.id);
    12480    }
    12581}
Note: See TracChangeset for help on using the changeset viewer.