- Timestamp:
- 2009-02-01T15:39:33+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.