Changeset 6092 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2013-07-30T18:24:18+02:00 (11 years ago)
Author:
akks
Message:

fix #7352: add "Paste tags" button to the relation editor

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  
    137137            @Override
    138138            public void updateTags(List<Tag> tags) {
    139                 GenericRelationEditor.this.updateTags(tags);
     139                tagEditorPanel.getModel().updateTags(tags);
    140140            }
    141141
     
    216216                }
    217217        );
     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());
    218223
    219224        tagEditorPanel.setNextFocusComponent(memberTable);
     
    427432        pnl3.add(splitPane, BorderLayout.CENTER);
    428433
    429         new PasteMembersAction();
    430         new CopyMembersAction();
    431         new PasteTagsAction();
    432 
    433434        return pnl3;
    434435    }
     
    696697    }
    697698
    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 
    726699    static class AddAbortException extends Exception {
    727700    }
     
    17181691    class PasteMembersAction extends AddFromSelectionAction {
    17191692
    1720         public PasteMembersAction() {
    1721             registerCopyPasteAction(this, "PASTE_MEMBERS", Shortcut.getPasteKeyStroke());
    1722         }
    1723 
    17241693        @Override
    17251694        public void actionPerformed(ActionEvent e) {
     
    17651734
    17661735    class CopyMembersAction extends AbstractAction {
    1767 
    1768         public CopyMembersAction() {
    1769             registerCopyPasteAction(this, "COPY_MEMBERS", Shortcut.getCopyKeyStroke());
    1770         }
    1771 
    17721736        @Override
    17731737        public void actionPerformed(ActionEvent e) {
     
    17831747    }
    17841748
    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         @Override
    1792         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 
    18011749    class MemberTableDblClickAdapter extends MouseAdapter {
    18021750        @Override
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r6087 r6092  
    2121import org.openstreetmap.josm.command.SequenceCommand;
    2222import org.openstreetmap.josm.data.osm.OsmPrimitive;
     23import org.openstreetmap.josm.data.osm.Tag;
    2324import org.openstreetmap.josm.data.osm.TagCollection;
    2425import org.openstreetmap.josm.data.osm.Tagged;
     
    576577
    577578    /**
     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    /**
    578609     * replies true, if this model has been updated
    579610     *
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java

    r6070 r6092  
    1010import java.awt.event.FocusEvent;
    1111import java.util.EnumSet;
     12import javax.swing.AbstractAction;
    1213
    1314import javax.swing.BoxLayout;
     
    8586        btn.setMargin(new Insets(0,0,0,0));
    8687        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);
    8793        return pnl;
     94    }
     95
     96    public AbstractAction getPasteAction() {
     97        return tagTable.getPasteAction();
    8898    }
    8999
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagTable.java

    r6070 r6092  
    1515import java.beans.PropertyChangeEvent;
    1616import java.beans.PropertyChangeListener;
     17import java.util.Collections;
    1718import java.util.EventObject;
     19import java.util.HashMap;
     20import java.util.List;
     21import java.util.Map;
    1822import java.util.concurrent.CopyOnWriteArrayList;
    1923
    2024import javax.swing.AbstractAction;
     25import static javax.swing.Action.SHORT_DESCRIPTION;
     26import static javax.swing.Action.SMALL_ICON;
    2127import javax.swing.CellEditor;
    2228import javax.swing.DefaultListSelectionModel;
     
    3238import javax.swing.table.TableColumn;
    3339import javax.swing.text.JTextComponent;
     40import org.openstreetmap.josm.Main;
     41import org.openstreetmap.josm.actions.PasteTagsAction.TagPaster;
     42import org.openstreetmap.josm.data.osm.OsmPrimitive;
     43import org.openstreetmap.josm.data.osm.Relation;
    3444
    3545import org.openstreetmap.josm.gui.dialogs.relation.RunnableAction;
     
    304314    }
    305315
     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   
    306345    /** the delete action */
    307346    private RunnableAction deleteAction = null;
     
    310349    private RunnableAction addAction = null;
    311350
     351    /** the tag paste action */
     352    private RunnableAction pasteAction = null;
     353
    312354    /**
    313355     *
     
    320362    public RunnableAction getAddAction() {
    321363        return addAction;
     364    }
     365
     366    public RunnableAction getPasteAction() {
     367        return pasteAction;
    322368    }
    323369
     
    353399        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_MASK), "addTag");
    354400        getActionMap().put("addTag", addAction);
     401
     402        pasteAction = new PasteAction();
    355403
    356404        // create the table cell editor and set it to key and value columns
Note: See TracChangeset for help on using the changeset viewer.