Changeset 1360 in josm
- Timestamp:
- 2009-02-01T15:39:33+01:00 (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/presets/presets.xml
r1358 r1360 8 8 --> 9 9 <!-- 10 item: 11 name: the text to display 12 icon: the icon to display 13 type: the data types - way,node,relation,closedway (separated by comma) 14 10 15 link: link to the relating map features website 11 16 … … 35 40 default: ticked on/off 36 41 delete_if_empty: true/false 42 43 See also http://josm.openstreetmap.de/wiki/TaggingPresets. 37 44 --> 38 45 <annotations> 39 46 <group name="Streets" icon="presets/way_secondary.png"> 40 <item name="Motorway" icon="presets/motorway.png" >47 <item name="Motorway" icon="presets/motorway.png" type="way"> 41 48 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=motorway" 42 49 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=motorway" /> … … 57 64 </optional> 58 65 </item> 59 <item name="Motorway Link" icon="presets/motorway.png" >66 <item name="Motorway Link" icon="presets/motorway.png" type="way"> 60 67 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=motorway_link" 61 68 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=motorway_link" /> … … 74 81 </optional> 75 82 </item> 76 <item name="Trunk" icon="presets/trunk.png" >83 <item name="Trunk" icon="presets/trunk.png" type="way"> 77 84 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=trunk" 78 85 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=trunk" /> … … 93 100 </optional> 94 101 </item> 95 <item name="Trunk Link" icon="presets/trunk.png" >102 <item name="Trunk Link" icon="presets/trunk.png" type="way"> 96 103 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=trunk_link" 97 104 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=trunk_link"/> … … 112 119 </item> 113 120 <separator/> 114 <item name="Primary" icon="presets/way_primary.png" >121 <item name="Primary" icon="presets/way_primary.png" type="way"> 115 122 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=primary" 116 123 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary" /> … … 131 138 </optional> 132 139 </item> 133 <item name="Primary Link" icon="presets/way_primary.png" >140 <item name="Primary Link" icon="presets/way_primary.png" type="way"> 134 141 <label text="Edit a Primary Link" /> 135 142 <space /> … … 146 153 </optional> 147 154 </item> 148 <item name="Secondary" icon="presets/way_secondary.png" >155 <item name="Secondary" icon="presets/way_secondary.png" type="way"> 149 156 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=secondary" 150 157 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=secondary" … … 166 173 </optional> 167 174 </item> 168 <item name="Tertiary" icon="presets/way_tertiary.png" >175 <item name="Tertiary" icon="presets/way_tertiary.png" type="way"> 169 176 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=tertiary" 170 177 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=tertiary" … … 185 192 </optional> 186 193 </item> 187 <item name="Unclassified" icon="presets/way_unclassified.png" >194 <item name="Unclassified" icon="presets/way_unclassified.png" type="way"> 188 195 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=unclassified" 189 196 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=unclassified" … … 204 211 </optional> 205 212 </item> 206 <item name="Residential" icon="presets/residential.png" >213 <item name="Residential" icon="presets/residential.png" type="way"> 207 214 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=residential" 208 215 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=residential" /> … … 222 229 </optional> 223 230 </item> 224 <item name="Living Street" icon="presets/living_street.png" >231 <item name="Living Street" icon="presets/living_street.png" type="way"> 225 232 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=living_street" 226 233 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=living_street" /> … … 240 247 </optional> 241 248 </item> 242 <item name="Service" icon="presets/way_unclassified.png" >249 <item name="Service" icon="presets/way_unclassified.png" type="way"> 243 250 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=service" 244 251 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=service" /> … … 259 266 </optional> 260 267 </item> 261 <item name="Parking Aisle" icon="presets/way_unclassified.png" >268 <item name="Parking Aisle" icon="presets/way_unclassified.png" type="way"> 262 269 <link href="http://wiki.openstreetmap.org/wiki/Tag:service=parking_aisle" 263 270 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:service=parking_aisle" … … 273 280 </item> 274 281 <separator/> 275 <item name="Road (Unknown Type)" icon="presets/way_unclassified.png" >276 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=road" 282 <item name="Road (Unknown Type)" icon="presets/way_unclassified.png" type="way"> 283 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=road" 277 284 de:href="http://wiki.openstreetmap.org/wiki/DE:Tag:highway=road" /> 278 285 <label text="Edit a Road of unknown type" /> … … 2864 2871 </item> 2865 2872 </group> <!-- Natural --> 2866 <!-- FIXME: parameter type and element role not yet supported! --> 2867 <!-- type should be used for all other items also to say if they are used for nodes/ways --> 2873 <!-- FIXME: element role not yet supported! --> 2868 2874 <group name="Relations" icon="presets/empty.png"> 2869 2875 <item name="Multipolygon" icon="presets/empty.png" type="relation"> -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r1349 r1360 2 2 package org.openstreetmap.josm.gui.tagging; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import static org.openstreetmap.josm.tools.I18n.trn; … … 14 15 import java.io.Reader; 15 16 import java.io.UnsupportedEncodingException; 17 import java.util.Arrays; 16 18 import java.util.Collection; 17 19 import java.util.HashMap; … … 39 41 import org.openstreetmap.josm.data.osm.OsmPrimitive; 40 42 import org.openstreetmap.josm.data.osm.OsmUtils; 43 import org.openstreetmap.josm.data.osm.Node; 44 import org.openstreetmap.josm.data.osm.Way; 45 import org.openstreetmap.josm.data.osm.Relation; 41 46 import org.openstreetmap.josm.io.MirroredInputStream; 42 47 import org.openstreetmap.josm.gui.QuadStateCheckBox; … … 412 417 * The types as preparsed collection. 413 418 */ 414 public Collection<Class<?>> types;419 public List<String> types; 415 420 public List<Item> data = new LinkedList<Item>(); 416 421 private static HashMap<String,String> lastValue = new HashMap<String,String>(); … … 462 467 * Called from the XML parser to set the types this preset affects 463 468 */ 469 private static Collection<String> allowedtypes = Arrays.asList(new String[] 470 {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")}); 464 471 public void setType(String types) throws SAXException { 465 try { 466 for (String type : types.split(",")) { 467 type = Character.toUpperCase(type.charAt(0))+type.substring(1); 468 if (this.types == null) 469 this.types = new LinkedList<Class<?>>(); 470 this.types.add(Class.forName("org.openstreetmap.josm.data.osm."+type)); 471 } 472 } catch (ClassNotFoundException e) { 473 e.printStackTrace(); 474 throw new SAXException(tr("Unknown type")); 472 this.types = Arrays.asList(types.split(",")); 473 for (String type : this.types) { 474 if(!allowedtypes.contains(type)) 475 throw new SAXException(tr("Unknown type: {0}", type)); 475 476 } 476 477 } … … 563 564 JPanel p = new JPanel(new GridBagLayout()); 564 565 LinkedList<Item> l = new LinkedList<Item>(); 566 if(types != null) 567 { 568 JPanel pp = new JPanel(); 569 for(String t : types) 570 { 571 JLabel la = new JLabel(ImageProvider.get("Mf_" + t)); 572 la.setToolTipText(tr("Elements of type {0} are supported.", tr(t))); 573 pp.add(la); 574 } 575 p.add(pp, GBC.eol()); 576 } 565 577 566 578 for (Item i : data) … … 577 589 578 590 public void actionPerformed(ActionEvent e) { 579 Collection<OsmPrimitive> sel = Main.ds.getSelected();591 Collection<OsmPrimitive> sel = createSelection(Main.ds.getSelected()); 580 592 JPanel p = createPanel(sel); 581 593 if (p == null) … … 593 605 } 594 606 }; 595 optionPane.createDialog(Main.parent, trn("Change {0} object", "Change {0} objects", sel.size(), sel.size())).setVisible(true); 607 String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size()); 608 if(sel.size() == 0) 609 title = tr("Nothing selected!"); 610 611 optionPane.createDialog(Main.parent, title).setVisible(true); 596 612 Object answerObj = optionPane.getValue(); 597 613 if (answerObj == null || answerObj == JOptionPane.UNINITIALIZED_VALUE || … … 599 615 answer = JOptionPane.CANCEL_OPTION; 600 616 } 601 if ( answer == JOptionPane.OK_OPTION) {602 Command cmd = createCommand( Main.ds.getSelected());617 if (sel.size() != 0 && answer == JOptionPane.OK_OPTION) { 618 Command cmd = createCommand(sel); 603 619 if (cmd != null) 604 620 Main.main.undoRedo.add(cmd); … … 607 623 } 608 624 609 private Co mmand createCommand(Collection<OsmPrimitive> participants) {625 private Collection<OsmPrimitive> createSelection(Collection<OsmPrimitive> participants) { 610 626 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(); 611 627 for (OsmPrimitive osm : participants) 612 if (types == null || types.contains(osm.getClass())) 613 sel.add(osm); 614 if (sel.isEmpty()) 615 return null; 616 628 { 629 if (types != null) 630 { 631 if(osm instanceof Relation) 632 { 633 if(!types.contains("relation")) continue; 634 } 635 else if(osm instanceof Node) 636 { 637 if(!types.contains("node")) continue; 638 } 639 else if(osm instanceof Way) 640 { 641 if(!types.contains("way") && 642 !(types.contains("closedway") && ((Way)osm).isClosed())) 643 continue; 644 } 645 } 646 sel.add(osm); 647 } 648 return sel; 649 } 650 651 private Command createCommand(Collection<OsmPrimitive> sel) { 617 652 List<Command> cmds = new LinkedList<Command>(); 618 653 for (Item i : data)
Note:
See TracChangeset
for help on using the changeset viewer.