Ignore:
Timestamp:
2009-07-19T19:04:49+02:00 (15 years ago)
Author:
Gubaer
Message:

removed dependencies to Main.ds, removed Main.ds
removed AddVisitor, NameVisitor, DeleteVisitor - unnecessary double dispatching for these simple cases

File:
1 edited

Legend:

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

    r1750 r1814  
    4545
    4646    public void actionPerformed(ActionEvent e) {
    47         if(noSelection()) return;
     47        if(isEmptySelection()) return;
    4848
    4949        Main.pasteBuffer = copyData();
    50         Main.pasteSource = Main.main.createOrGetEditLayer();
     50        Main.pasteSource = getEditLayer();
    5151        Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */
    5252
     
    5656    }
    5757
    58     public static DataSet copyData() {
     58    public DataSet copyData() {
    5959        /* New pasteBuffer - will be assigned to the global one at the end */
    6060        final DataSet pasteBuffer = new DataSet();
     
    6262        /* temporarily maps old nodes to new so we can do a true deep copy */
    6363
    64         if(noSelection()) return pasteBuffer;
     64        if(isEmptySelection()) return pasteBuffer;
    6565
    6666        /* scan the selected objects, mapping them to copies; when copying a way or relation,
     
    7171                 * or a way and a node in that way is selected, we'll see it twice, once via the
    7272                 * way and once directly; and so on. */
    73                 if (map.containsKey(n)) { return; }
     73                if (map.containsKey(n))
     74                    return;
    7475                Node nnew = new Node(n);
    7576                map.put(n, nnew);
     
    7879            public void visit(Way w) {
    7980                /* check if already in pasteBuffer - could have come from a relation, and directly etc. */
    80                 if (map.containsKey(w)) { return; }
     81                if (map.containsKey(w))
     82                    return;
    8183                Way wnew = new Way();
    8284                wnew.cloneFrom(w);
     
    9395            }
    9496            public void visit(Relation e) {
    95                 if (map.containsKey(e)) { return; }
     97                if (map.containsKey(e))
     98                    return;
    9699                Relation enew = new Relation(e);
    97100                List<RelationMember> members = new ArrayList<RelationMember>();
     
    108111            }
    109112            public void visitAll() {
    110                 for (OsmPrimitive osm : Main.ds.getSelected())
     113                for (OsmPrimitive osm : getCurrentDataSet().getSelected()) {
    111114                    osm.visit(this);
     115                }
    112116
    113117                // Used internally only (in PasteTagsAction), therefore no need to translate these
    114                 if(Main.ds.getSelectedNodes().size() > 0)
     118                if(getCurrentDataSet().getSelectedNodes().size() > 0) {
    115119                    pasteBuffer.dataSources.add(new DataSource(null, "Copied Nodes"));
    116                 if(Main.ds.getSelectedWays().size() > 0)
     120                }
     121                if(getCurrentDataSet().getSelectedWays().size() > 0) {
    117122                    pasteBuffer.dataSources.add(new DataSource(null, "Copied Ways"));
    118                 if(Main.ds.getSelectedRelations().size() > 0)
     123                }
     124                if(getCurrentDataSet().getSelectedRelations().size() > 0) {
    119125                    pasteBuffer.dataSources.add(new DataSource(null, "Copied Relations"));
     126                }
    120127            }
    121128        }.visitAll();
     
    128135    }
    129136
    130     private static boolean noSelection() {
    131         Collection<OsmPrimitive> sel = Main.ds.getSelected();
     137    private boolean isEmptySelection() {
     138        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
    132139        if (sel.isEmpty()) {
    133             JOptionPane.showMessageDialog(Main.parent,
    134                     tr("Please select something to copy."));
     140            JOptionPane.showMessageDialog(
     141                    Main.parent,
     142                    tr("Please select something to copy.")
     143            );
    135144            return true;
    136145        }
Note: See TracChangeset for help on using the changeset viewer.