Changeset 3640 in josm
- Timestamp:
- 2010-10-24T15:07:01+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r3385 r3640 23 23 import org.openstreetmap.josm.data.osm.PrimitiveData; 24 24 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy; 25 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy.PasteBufferChangedListener; 26 import org.openstreetmap.josm.data.osm.Tag; 25 27 import org.openstreetmap.josm.data.osm.TagCollection; 26 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy.PasteBufferChangedListener;27 28 import org.openstreetmap.josm.gui.conflict.tags.PasteTagsConflictResolverDialog; 28 29 import org.openstreetmap.josm.tools.Shortcut; … … 42 43 private final Collection<PrimitiveData> source; 43 44 private final Collection<OsmPrimitive> target; 44 private final List< Command> commands = new ArrayList<Command>();45 private final List<Tag> commands = new ArrayList<Tag>(); 45 46 46 47 public TagPaster(Collection<PrimitiveData> source, Collection<OsmPrimitive> target) { … … 100 101 } 101 102 102 protected Command buildChangeCommand(Collection<? extends OsmPrimitive> selection, TagCollection tc) { 103 List<Command> commands = new ArrayList<Command>(); 103 protected void buildChangeCommand(Collection<? extends OsmPrimitive> selection, TagCollection tc) { 104 104 for (String key : tc.getKeys()) { 105 String value = tc.getValues(key).iterator().next(); 106 value = value.equals("") ? null : value; 107 commands.add(new ChangePropertyCommand(selection,key,value)); 108 } 109 if (!commands.isEmpty()) { 110 String title1 = trn("Pasting {0} tag", "Pasting {0} tags", tc.getKeys().size(), tc.getKeys().size()); 111 String title2 = trn("to {0} primitive", "to {0} primtives", selection.size(), selection.size()); 112 return new SequenceCommand( 113 title1 + " " + title2, 114 commands 115 ); 116 } 117 return null; 105 commands.add(new Tag(key, tc.getValues(key).iterator().next())); 106 } 118 107 } 119 108 … … 166 155 if (dialog.isCanceled()) 167 156 return; 168 Command cmd = buildChangeCommand(target, dialog.getResolution()); 169 commands.add(cmd); 157 buildChangeCommand(target, dialog.getResolution()); 170 158 } else { 171 159 // no conflicts in the source tags to resolve. Just apply the tags 172 160 // to the target primitives 173 161 // 174 Command cmd = buildChangeCommand(target, tc); 175 commands.add(cmd); 162 buildChangeCommand(target, tc); 176 163 } 177 164 } … … 218 205 for (OsmPrimitiveType type:OsmPrimitiveType.values()) { 219 206 if (hasSourceTagsByType(type) && hasTargetPrimitives(type.getOsmClass())) { 220 Command cmd = buildChangeCommand(target, getSourceTagsByType(type)); 221 commands.add(cmd); 207 buildChangeCommand(target, getSourceTagsByType(type)); 222 208 } 223 209 } … … 236 222 for (OsmPrimitiveType type:OsmPrimitiveType.values()) { 237 223 if (hasSourceTagsByType(type) && hasTargetPrimitives(type.getOsmClass())) { 238 Command cmd = buildChangeCommand(OsmPrimitive.getFilteredList(target, type.getOsmClass()), dialog.getResolution(type)); 239 commands.add(cmd); 224 buildChangeCommand(OsmPrimitive.getFilteredList(target, type.getOsmClass()), dialog.getResolution(type)); 240 225 } 241 226 } … … 243 228 } 244 229 245 public List< Command> execute() {230 public List<Tag> execute() { 246 231 commands.clear(); 247 232 if (isHeteogeneousSource()) { … … 256 241 257 242 public void actionPerformed(ActionEvent e) { 258 if (getCurrentDataSet().getSelected().isEmpty()) 243 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 244 245 if (selection.isEmpty()) 259 246 return; 260 TagPaster tagPaster = new TagPaster(Main.pasteBuffer.getDirectlyAdded(), getCurrentDataSet().getSelected()); 261 for (Command c:tagPaster.execute()) { 262 Main.main.undoRedo.add(c); 263 } 247 248 TagPaster tagPaster = new TagPaster(Main.pasteBuffer.getDirectlyAdded(), selection); 249 250 List<Command> commands = new ArrayList<Command>(); 251 for (Tag tag: tagPaster.execute()) { 252 commands.add(new ChangePropertyCommand(selection, tag.getKey(), "".equals(tag.getValue())?null:tag.getValue())); 253 } 254 if (!commands.isEmpty()) { 255 String title1 = trn("Pasting {0} tag", "Pasting {0} tags", commands.size(), commands.size()); 256 String title2 = trn("to {0} primitive", "to {0} primtives", selection.size(), selection.size()); 257 Main.main.undoRedo.add( 258 new SequenceCommand( 259 title1 + " " + title2, 260 commands 261 )); 262 } 263 264 264 } 265 265 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r3561 r3640 54 54 import org.openstreetmap.josm.Main; 55 55 import org.openstreetmap.josm.actions.CopyAction; 56 import org.openstreetmap.josm.actions.PasteTagsAction.TagPaster; 56 57 import org.openstreetmap.josm.command.AddCommand; 57 58 import org.openstreetmap.josm.command.ChangeCommand; … … 132 133 @Override 133 134 public void updateTags(List<Tag> tags) { 134 Map<String, TagModel> modelTags = new HashMap<String, TagModel>(); 135 for (int i=0; i<tagEditorPanel.getModel().getRowCount(); i++) { 136 TagModel tagModel = tagEditorPanel.getModel().get(i); 137 modelTags.put(tagModel.getName(), tagModel); 138 } 139 for (Tag tag: tags) { 140 TagModel existing = modelTags.get(tag.getKey()); 141 142 if (tag.getValue().isEmpty()) { 143 if (existing != null) { 144 tagEditorPanel.getModel().delete(tag.getKey()); 145 } 146 } else { 147 if (existing != null) { 148 tagEditorPanel.getModel().updateTagValue(existing, tag.getValue()); 149 } else { 150 tagEditorPanel.getModel().add(tag.getKey(), tag.getValue()); 151 } 152 } 153 154 } 135 GenericRelationEditor.this.updateTags(tags); 155 136 } 156 137 … … 429 410 new PasteMembersAction(); 430 411 new CopyMembersAction(); 412 new PasteTagsAction(); 431 413 432 414 return pnl3; … … 650 632 } 651 633 634 protected void updateTags(List<Tag> tags) { 635 636 if (tags.isEmpty()) 637 return; 638 639 Map<String, TagModel> modelTags = new HashMap<String, TagModel>(); 640 for (int i=0; i<tagEditorPanel.getModel().getRowCount(); i++) { 641 TagModel tagModel = tagEditorPanel.getModel().get(i); 642 modelTags.put(tagModel.getName(), tagModel); 643 } 644 for (Tag tag: tags) { 645 TagModel existing = modelTags.get(tag.getKey()); 646 647 if (tag.getValue().isEmpty()) { 648 if (existing != null) { 649 tagEditorPanel.getModel().delete(tag.getKey()); 650 } 651 } else { 652 if (existing != null) { 653 tagEditorPanel.getModel().updateTagValue(existing, tag.getValue()); 654 } else { 655 tagEditorPanel.getModel().add(tag.getKey(), tag.getValue()); 656 } 657 } 658 659 } 660 } 661 652 662 static class AddAbortException extends Exception { 653 663 } … … 1565 1575 } 1566 1576 1577 class PasteTagsAction extends AbstractAction { 1578 1579 public PasteTagsAction() { 1580 registerCopyPasteAction(this, "PASTE_TAGS", Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT).getKeyStroke()); 1581 } 1582 1583 @Override 1584 public void actionPerformed(ActionEvent e) { 1585 Relation relation = new Relation(); 1586 tagEditorPanel.getModel().applyToPrimitive(relation); 1587 TagPaster tagPaster = new TagPaster(Main.pasteBuffer.getDirectlyAdded(), Collections.<OsmPrimitive>singletonList(relation)); 1588 updateTags(tagPaster.execute()); 1589 } 1590 1591 } 1592 1567 1593 class MemberTableDblClickAdapter extends MouseAdapter { 1568 1594 @Override -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java
r3518 r3640 209 209 if (tag == null) { 210 210 tag = new TagModel(name, value); 211 tags.add(tag); 211 int index = tags.size(); 212 while (index >= 1 && tags.get(index - 1).getName().isEmpty() && tags.get(index - 1).getValue().isEmpty()) { 213 index--; // If last line(s) is empty, add new tag before it 214 } 215 tags.add(index, tag); 212 216 } else { 213 217 tag.addValue(value);
Note:
See TracChangeset
for help on using the changeset viewer.