Changeset 750 in josm for trunk


Ignore:
Timestamp:
2008-08-06T15:51:12+02:00 (16 years ago)
Author:
stoecker
Message:

Fixed exception. Closes bug #1379.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java

    r655 r750  
    2323public final class PasteTagsAction extends JosmAction implements SelectionChangedListener {
    2424
    25     public PasteTagsAction(JosmAction copyAction) {
    26         super(tr("Paste Tags"), "pastetags",
     25        public PasteTagsAction(JosmAction copyAction) {
     26                super(tr("Paste Tags"), "pastetags",
    2727                        tr("Apply tags of contents of paste buffer to all selected items."),
    2828                        KeyEvent.VK_V, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK, true);
     
    3030                copyAction.addListener(this);
    3131                setEnabled(false);
    32     }
     32        }
    3333
    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. 
     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.
    3636                 * If a tag already exists, it is overwritten */
    3737                if (selectionSubset != null && ! selectionSubset.isEmpty()) {
    3838                        for (Iterator<? extends OsmPrimitive> it = pasteBufferSubset.iterator(); it.hasNext();) {
    3939                                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                                        }
    4347                                }
    4448                        }
    45                 }       
    46     }
    47    
    48     public void actionPerformed(ActionEvent e) {
    49                 Collection<Command> clist = new LinkedList<Command>();         
     49                }
     50        }
     51
     52        public void actionPerformed(ActionEvent e) {
     53                Collection<Command> clist = new LinkedList<Command>();
    5054                pasteKeys(clist, Main.pasteBuffer.nodes, Main.ds.getSelectedNodes());
    5155                pasteKeys(clist, Main.pasteBuffer.ways, Main.ds.getSelectedWays());
     
    5458                Main.ds.setSelected(Main.ds.getSelected()); // to force selection listeners, in particular the tag panel, to update
    5559                Main.map.mapView.repaint();
    56     }
    57    
     60        }
     61
    5862        private boolean containsSameKeysWithDifferentValues(Collection<? extends OsmPrimitive> osms) {
    5963                Map<String,String> kvSeen = new HashMap<String,String>();
     
    7175                                        return true;
    7276                        }
    73                 }               
     77                }
    7478                return false;
    7579        }
    76        
     80
    7781        /**
    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
    8084         * @param pasteBuffer
    8185         */
    8286        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
    8488                        if we don't have conflicting keys in the pastebuffer */
    8589                setEnabled(selection != null &&
    8690                                ! selection.isEmpty() &&
    87                                 ! pasteBuffer.allPrimitives().isEmpty() && 
     91                                ! pasteBuffer.allPrimitives().isEmpty() &&
    8892                                (Main.ds.getSelectedNodes().isEmpty() ||
    89                                         ! containsSameKeysWithDifferentValues(pasteBuffer.nodes)) && 
     93                                        ! containsSameKeysWithDifferentValues(pasteBuffer.nodes)) &&
    9094                                (Main.ds.getSelectedWays().isEmpty() ||
    91                                         ! containsSameKeysWithDifferentValues(pasteBuffer.ways)) && 
     95                                        ! containsSameKeysWithDifferentValues(pasteBuffer.ways)) &&
    9296                                (Main.ds.getSelectedRelations().isEmpty() ||
    9397                                        ! containsSameKeysWithDifferentValues(pasteBuffer.relations)));
    9498        }
    95        
     99
    96100        @Override public void pasteBufferChanged(DataSet newPasteBuffer) {
    97101                possiblyEnable(Main.ds.getSelected(), newPasteBuffer);
    98102        }
    99        
     103
    100104        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    101105                possiblyEnable(newSelection, Main.pasteBuffer);
Note: See TracChangeset for help on using the changeset viewer.