Ignore:
Timestamp:
2006-07-21T13:49:09+02:00 (19 years ago)
Author:
imi
Message:
  • added type={node,segment,way} feature to annotation presets
  • fixed missing close when reading annotation presets
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/dialogs/AnnotationPreset.java

    r117 r120  
    132132                List<Item> current;
    133133                String currentName;
     134                Class<?> currentType;
    134135                private static int unknownCounter = 1;
    135136
     
    142143                                if (currentName == null)
    143144                                        currentName = "Unnamed Preset #"+(unknownCounter++);
     145                                if (a.getValue("type") != null) {
     146                                        String s = a.getValue("type");
     147                                        s = Character.toUpperCase(s.charAt(0))+s.substring(1);
     148                                        try {
     149                                                currentType = Class.forName("org.openstreetmap.josm.data.osm."+s);
     150                                        } catch (ClassNotFoundException e) {
     151                                                e.printStackTrace();
     152                                                throw new SAXException(tr("Unknown type at line {0}", getLineNumber()));
     153                                        }
     154                                }
    144155                        } else if (qname.equals("text"))
    145156                                current.add(new Text(a.getValue("key"), a.getValue("text"), a.getValue("default")));
     
    160171                                throw new SAXException(tr("Unknown annotation object {0} at line {1} column {2}", qname, getLineNumber(), getColumnNumber()));
    161172                }
     173
    162174                @Override public void endElement(String ns, String lname, String qname) {
    163175                        if (qname.equals("item"))
    164                                 data.add(new AnnotationPreset(current, currentName));
     176                                data.add(new AnnotationPreset(current, currentName, currentType));
    165177                }
    166178        }
     
    168180        private List<Item> data;
    169181        String name;
    170 
    171         public AnnotationPreset(List<Item> data, String name) {
     182        private Class<?> type;
     183
     184        public AnnotationPreset(List<Item> data, String name, Class<?> currentType) {
    172185                this.data = data;
    173186                this.name = name;
     187                this.type = currentType;
    174188        }
    175189
     
    209223        }
    210224
    211         public Command createCommand(Collection<OsmPrimitive> sel) {
     225        public Command createCommand(Collection<OsmPrimitive> participants) {
     226                Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>();
     227                for (OsmPrimitive osm : participants)
     228                        if (osm.getClass() == type)
     229                                sel.add(osm);
     230                if (sel.isEmpty())
     231                        return null;
     232
    212233                List<Command> cmds = new LinkedList<Command>();
    213234                for (Item i : data)
Note: See TracChangeset for help on using the changeset viewer.