- Timestamp:
- 2013-07-30T18:24:18+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r6087 r6092 137 137 @Override 138 138 public void updateTags(List<Tag> tags) { 139 GenericRelationEditor.this.updateTags(tags);139 tagEditorPanel.getModel().updateTags(tags); 140 140 } 141 141 … … 216 216 } 217 217 ); 218 registerCopyPasteAction(tagEditorPanel.getPasteAction(), 219 "PASTE_TAGS", 220 Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.CTRL_SHIFT).getKeyStroke()); 221 registerCopyPasteAction(new PasteMembersAction(), "PASTE_MEMBERS", Shortcut.getPasteKeyStroke()); 222 registerCopyPasteAction(new CopyMembersAction(), "COPY_MEMBERS", Shortcut.getCopyKeyStroke()); 218 223 219 224 tagEditorPanel.setNextFocusComponent(memberTable); … … 427 432 pnl3.add(splitPane, BorderLayout.CENTER); 428 433 429 new PasteMembersAction();430 new CopyMembersAction();431 new PasteTagsAction();432 433 434 return pnl3; 434 435 } … … 696 697 } 697 698 698 protected void updateTags(List<Tag> tags) {699 700 if (tags.isEmpty())701 return;702 703 Map<String, TagModel> modelTags = new HashMap<String, TagModel>();704 for (int i=0; i<tagEditorPanel.getModel().getRowCount(); i++) {705 TagModel tagModel = tagEditorPanel.getModel().get(i);706 modelTags.put(tagModel.getName(), tagModel);707 }708 for (Tag tag: tags) {709 TagModel existing = modelTags.get(tag.getKey());710 711 if (tag.getValue().isEmpty()) {712 if (existing != null) {713 tagEditorPanel.getModel().delete(tag.getKey());714 }715 } else {716 if (existing != null) {717 tagEditorPanel.getModel().updateTagValue(existing, tag.getValue());718 } else {719 tagEditorPanel.getModel().add(tag.getKey(), tag.getValue());720 }721 }722 723 }724 }725 726 699 static class AddAbortException extends Exception { 727 700 } … … 1718 1691 class PasteMembersAction extends AddFromSelectionAction { 1719 1692 1720 public PasteMembersAction() {1721 registerCopyPasteAction(this, "PASTE_MEMBERS", Shortcut.getPasteKeyStroke());1722 }1723 1724 1693 @Override 1725 1694 public void actionPerformed(ActionEvent e) { … … 1765 1734 1766 1735 class CopyMembersAction extends AbstractAction { 1767 1768 public CopyMembersAction() {1769 registerCopyPasteAction(this, "COPY_MEMBERS", Shortcut.getCopyKeyStroke());1770 }1771 1772 1736 @Override 1773 1737 public void actionPerformed(ActionEvent e) { … … 1783 1747 } 1784 1748 1785 class PasteTagsAction extends AbstractAction {1786 1787 public PasteTagsAction() {1788 registerCopyPasteAction(this, "PASTE_TAGS", Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.CTRL_SHIFT).getKeyStroke());1789 }1790 1791 @Override1792 public void actionPerformed(ActionEvent e) {1793 Relation relation = new Relation();1794 tagEditorPanel.getModel().applyToPrimitive(relation);1795 TagPaster tagPaster = new TagPaster(Main.pasteBuffer.getDirectlyAdded(), Collections.<OsmPrimitive>singletonList(relation));1796 updateTags(tagPaster.execute());1797 }1798 1799 }1800 1801 1749 class MemberTableDblClickAdapter extends MouseAdapter { 1802 1750 @Override -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java
r6087 r6092 21 21 import org.openstreetmap.josm.command.SequenceCommand; 22 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.Tag; 23 24 import org.openstreetmap.josm.data.osm.TagCollection; 24 25 import org.openstreetmap.josm.data.osm.Tagged; … … 576 577 577 578 /** 579 * Load tags from given list 580 * @param tags - the list 581 */ 582 public void updateTags(List<Tag> tags) { 583 if (tags.isEmpty()) 584 return; 585 586 Map<String, TagModel> modelTags = new HashMap<String, TagModel>(); 587 for (int i=0; i<getRowCount(); i++) { 588 TagModel tagModel = get(i); 589 modelTags.put(tagModel.getName(), tagModel); 590 } 591 for (Tag tag: tags) { 592 TagModel existing = modelTags.get(tag.getKey()); 593 594 if (tag.getValue().isEmpty()) { 595 if (existing != null) { 596 delete(tag.getKey()); 597 } 598 } else { 599 if (existing != null) { 600 updateTagValue(existing, tag.getValue()); 601 } else { 602 add(tag.getKey(), tag.getValue()); 603 } 604 } 605 } 606 } 607 608 /** 578 609 * replies true, if this model has been updated 579 610 * -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java
r6070 r6092 10 10 import java.awt.event.FocusEvent; 11 11 import java.util.EnumSet; 12 import javax.swing.AbstractAction; 12 13 13 14 import javax.swing.BoxLayout; … … 85 86 btn.setMargin(new Insets(0,0,0,0)); 86 87 tagTable.addComponentNotStoppingCellEditing(btn); 88 89 // paste action 90 pnl.add(btn = new JButton(tagTable.getPasteAction())); 91 btn.setMargin(new Insets(0,0,0,0)); 92 tagTable.addComponentNotStoppingCellEditing(btn); 87 93 return pnl; 94 } 95 96 public AbstractAction getPasteAction() { 97 return tagTable.getPasteAction(); 88 98 } 89 99 -
trunk/src/org/openstreetmap/josm/gui/tagging/TagTable.java
r6070 r6092 15 15 import java.beans.PropertyChangeEvent; 16 16 import java.beans.PropertyChangeListener; 17 import java.util.Collections; 17 18 import java.util.EventObject; 19 import java.util.HashMap; 20 import java.util.List; 21 import java.util.Map; 18 22 import java.util.concurrent.CopyOnWriteArrayList; 19 23 20 24 import javax.swing.AbstractAction; 25 import static javax.swing.Action.SHORT_DESCRIPTION; 26 import static javax.swing.Action.SMALL_ICON; 21 27 import javax.swing.CellEditor; 22 28 import javax.swing.DefaultListSelectionModel; … … 32 38 import javax.swing.table.TableColumn; 33 39 import javax.swing.text.JTextComponent; 40 import org.openstreetmap.josm.Main; 41 import org.openstreetmap.josm.actions.PasteTagsAction.TagPaster; 42 import org.openstreetmap.josm.data.osm.OsmPrimitive; 43 import org.openstreetmap.josm.data.osm.Relation; 34 44 35 45 import org.openstreetmap.josm.gui.dialogs.relation.RunnableAction; … … 304 314 } 305 315 316 /** 317 * Action to be run when the user wants to paste tags from buffer 318 */ 319 class PasteAction extends RunnableAction implements PropertyChangeListener{ 320 public PasteAction() { 321 putValue(SMALL_ICON, ImageProvider.get("","pastetags")); 322 putValue(SHORT_DESCRIPTION, tr("Paste tags from buffer")); 323 TagTable.this.addPropertyChangeListener(this); 324 updateEnabledState(); 325 } 326 327 @Override 328 public void run() { 329 Relation relation = new Relation(); 330 model.applyToPrimitive(relation); 331 TagPaster tagPaster = new TagPaster(Main.pasteBuffer.getDirectlyAdded(), Collections.<OsmPrimitive>singletonList(relation)); 332 model.updateTags(tagPaster.execute()); 333 } 334 335 protected void updateEnabledState() { 336 setEnabled(TagTable.this.isEnabled()); 337 } 338 339 @Override 340 public void propertyChange(PropertyChangeEvent evt) { 341 updateEnabledState(); 342 } 343 } 344 306 345 /** the delete action */ 307 346 private RunnableAction deleteAction = null; … … 310 349 private RunnableAction addAction = null; 311 350 351 /** the tag paste action */ 352 private RunnableAction pasteAction = null; 353 312 354 /** 313 355 * … … 320 362 public RunnableAction getAddAction() { 321 363 return addAction; 364 } 365 366 public RunnableAction getPasteAction() { 367 return pasteAction; 322 368 } 323 369 … … 353 399 .put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_MASK), "addTag"); 354 400 getActionMap().put("addTag", addAction); 401 402 pasteAction = new PasteAction(); 355 403 356 404 // create the table cell editor and set it to key and value columns
Note:
See TracChangeset
for help on using the changeset viewer.