- Timestamp:
- 2008-08-06T15:51:12+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r655 r750 23 23 public final class PasteTagsAction extends JosmAction implements SelectionChangedListener { 24 24 25 26 25 public PasteTagsAction(JosmAction copyAction) { 26 super(tr("Paste Tags"), "pastetags", 27 27 tr("Apply tags of contents of paste buffer to all selected items."), 28 28 KeyEvent.VK_V, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK, true); … … 30 30 copyAction.addListener(this); 31 31 setEnabled(false); 32 32 } 33 33 34 35 /* scan the paste buffer, and add tags to each of the selected objects. 34 private void pasteKeys(Collection<Command> clist, Collection<? extends OsmPrimitive> pasteBufferSubset, Collection<OsmPrimitive> selectionSubset) { 35 /* scan the paste buffer, and add tags to each of the selected objects. 36 36 * If a tag already exists, it is overwritten */ 37 37 if (selectionSubset != null && ! selectionSubset.isEmpty()) { 38 38 for (Iterator<? extends OsmPrimitive> it = pasteBufferSubset.iterator(); it.hasNext();) { 39 39 OsmPrimitive osm = it.next(); 40 for (String key : osm.keys.keySet()) { 41 if (! key.equals("created_by")) 42 clist.add(new ChangePropertyCommand(selectionSubset, key, osm.keys.get(key))); 40 Map<String, String> m = osm.keys; 41 if(m != null) 42 { 43 for (String key : m.keySet()) { 44 if (! key.equals("created_by")) 45 clist.add(new ChangePropertyCommand(selectionSubset, key, osm.keys.get(key))); 46 } 43 47 } 44 48 } 45 } 46 47 48 49 Collection<Command> clist = new LinkedList<Command>(); 49 } 50 } 51 52 public void actionPerformed(ActionEvent e) { 53 Collection<Command> clist = new LinkedList<Command>(); 50 54 pasteKeys(clist, Main.pasteBuffer.nodes, Main.ds.getSelectedNodes()); 51 55 pasteKeys(clist, Main.pasteBuffer.ways, Main.ds.getSelectedWays()); … … 54 58 Main.ds.setSelected(Main.ds.getSelected()); // to force selection listeners, in particular the tag panel, to update 55 59 Main.map.mapView.repaint(); 56 57 60 } 61 58 62 private boolean containsSameKeysWithDifferentValues(Collection<? extends OsmPrimitive> osms) { 59 63 Map<String,String> kvSeen = new HashMap<String,String>(); … … 71 75 return true; 72 76 } 73 } 77 } 74 78 return false; 75 79 } 76 80 77 81 /** 78 * Determines whether to enable the widget depending on the contents of the paste 79 * buffer and current selection 82 * Determines whether to enable the widget depending on the contents of the paste 83 * buffer and current selection 80 84 * @param pasteBuffer 81 85 */ 82 86 private void possiblyEnable(Collection<? extends OsmPrimitive> selection, DataSet pasteBuffer) { 83 /* only enable if there is something selected to paste into and 87 /* only enable if there is something selected to paste into and 84 88 if we don't have conflicting keys in the pastebuffer */ 85 89 setEnabled(selection != null && 86 90 ! selection.isEmpty() && 87 ! pasteBuffer.allPrimitives().isEmpty() && 91 ! pasteBuffer.allPrimitives().isEmpty() && 88 92 (Main.ds.getSelectedNodes().isEmpty() || 89 ! containsSameKeysWithDifferentValues(pasteBuffer.nodes)) && 93 ! containsSameKeysWithDifferentValues(pasteBuffer.nodes)) && 90 94 (Main.ds.getSelectedWays().isEmpty() || 91 ! containsSameKeysWithDifferentValues(pasteBuffer.ways)) && 95 ! containsSameKeysWithDifferentValues(pasteBuffer.ways)) && 92 96 (Main.ds.getSelectedRelations().isEmpty() || 93 97 ! containsSameKeysWithDifferentValues(pasteBuffer.relations))); 94 98 } 95 99 96 100 @Override public void pasteBufferChanged(DataSet newPasteBuffer) { 97 101 possiblyEnable(Main.ds.getSelected(), newPasteBuffer); 98 102 } 99 103 100 104 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 101 105 possiblyEnable(newSelection, Main.pasteBuffer);
Note:
See TracChangeset
for help on using the changeset viewer.