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/CombineWayAction.java

    r1621 r1814  
    5252    public CombineWayAction() {
    5353        super(tr("Combine Way"), "combineway", tr("Combine several ways into one."),
    54         Shortcut.registerShortcut("tools:combineway", tr("Tool: {0}", tr("Combine Way")), KeyEvent.VK_C, Shortcut.GROUP_EDIT), true);
     54                Shortcut.registerShortcut("tools:combineway", tr("Tool: {0}", tr("Combine Way")), KeyEvent.VK_C, Shortcut.GROUP_EDIT), true);
    5555        DataSet.selListeners.add(this);
    5656    }
    5757
    5858    public void actionPerformed(ActionEvent event) {
    59         Collection<OsmPrimitive> selection = Main.ds.getSelected();
     59        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    6060        LinkedList<Way> selectedWays = new LinkedList<Way>();
    6161
    6262        for (OsmPrimitive osm : selection)
    63             if (osm instanceof Way)
     63            if (osm instanceof Way) {
    6464                selectedWays.add((Way)osm);
     65            }
    6566
    6667        if (selectedWays.size() < 2) {
     
    8283            new HashMap<Pair<Relation,String>, HashSet<Way>>();
    8384        HashSet<Relation> relationsUsingWays = new HashSet<Relation>();
    84         for (Relation r : Main.ds.relations) {
    85             if (r.deleted || r.incomplete) continue;
     85        for (Relation r : getCurrentDataSet().relations) {
     86            if (r.deleted || r.incomplete) {
     87                continue;
     88            }
    8689            for (RelationMember rm : r.members) {
    8790                if (rm.member instanceof Way) {
     
    112115                        tr("Combine ways with different memberships?"),
    113116                        tr("The selected ways have differing relation memberships.  "
    114                             + "Do you still want to combine them?"),
    115                         new String[] {tr("Combine Anyway"), tr("Cancel")},
    116                         new String[] {"combineway.png", "cancel.png"}).getValue();
    117                 if (option == 1) break;
     117                                + "Do you still want to combine them?"),
     118                                new String[] {tr("Combine Anyway"), tr("Cancel")},
     119                                new String[] {"combineway.png", "cancel.png"}).getValue();
     120                if (option == 1) {
     121                    break;
     122                }
    118123
    119124                return;
     
    125130        for (Way w : selectedWays) {
    126131            for (Entry<String,String> e : w.entrySet()) {
    127                 if (!props.containsKey(e.getKey()))
     132                if (!props.containsKey(e.getKey())) {
    128133                    props.put(e.getKey(), new TreeSet<String>());
     134                }
    129135                props.get(e.getKey()).add(e.getValue());
    130136            }
     
    139145            if (secondTry instanceof List) {
    140146                int option = new ExtendedDialog(Main.parent,
    141                     tr("Change directions?"),
    142                     tr("The ways can not be combined in their current directions.  "
    143                         + "Do you want to reverse some of them?"),
    144                     new String[] {tr("Reverse and Combine"), tr("Cancel")},
    145                     new String[] {"wayflip.png", "cancel.png"}).getValue();
     147                        tr("Change directions?"),
     148                        tr("The ways can not be combined in their current directions.  "
     149                                + "Do you want to reverse some of them?"),
     150                                new String[] {tr("Reverse and Combine"), tr("Cancel")},
     151                                new String[] {"wayflip.png", "cancel.png"}).getValue();
    146152                if (option != 1) return;
    147153                nodeList = (List<Node>) secondTry;
     
    160166        for (Way w : selectedWays) {
    161167            modifyWay = w;
    162             if (w.id != 0) break;
     168            if (w.id != 0) {
     169                break;
     170            }
    163171        }
    164172        Way newWay = new Way(modifyWay);
     
    188196        if (!components.isEmpty()) {
    189197            int answer = new ExtendedDialog(Main.parent,
    190                 tr("Enter values for all conflicts."),
    191                 p,
    192                 new String[] {tr("Solve Conflicts"), tr("Cancel")},
    193                 new String[] {"dialogs/conflict.png", "cancel.png"}).getValue();
     198                    tr("Enter values for all conflicts."),
     199                    p,
     200                    new String[] {tr("Solve Conflicts"), tr("Cancel")},
     201                    new String[] {"dialogs/conflict.png", "cancel.png"}).getValue();
    194202            if (answer != 1) return;
    195203
    196             for (Entry<String, JComboBox> e : components.entrySet())
     204            for (Entry<String, JComboBox> e : components.entrySet()) {
    197205                newWay.put(e.getKey(), e.getValue().getEditor().getItem().toString());
     206            }
    198207        }
    199208
     
    224233        }
    225234        Main.main.undoRedo.add(new SequenceCommand(tr("Combine {0} ways", selectedWays.size()), cmds));
    226         Main.ds.setSelected(modifyWay);
     235        getCurrentDataSet().setSelected(modifyWay);
    227236    }
    228237
     
    242251
    243252        HashSet<Pair<Node,Node>> chunkSet = new HashSet<Pair<Node,Node>>();
    244         for (Way w : ways)
     253        for (Way w : ways) {
    245254            chunkSet.addAll(w.getNodePairs(ignoreDirection));
     255        }
    246256
    247257        LinkedList<Pair<Node,Node>> chunks = new LinkedList<Pair<Node,Node>>(chunkSet);
    248258
    249         if (chunks.isEmpty()) {
     259        if (chunks.isEmpty())
    250260            return tr("All the ways were empty");
    251         }
    252261
    253262        List<Node> nodeList = Pair.toArrayList(chunks.poll());
     
    273282                break;
    274283            }
    275             if (!foundChunk) break;
    276         }
    277 
    278         if (!chunks.isEmpty()) {
     284            if (!foundChunk) {
     285                break;
     286            }
     287        }
     288
     289        if (!chunks.isEmpty())
    279290            return tr("Could not combine ways "
    280                 + "(They could not be merged into a single string of nodes)");
    281         }
     291                    + "(They could not be merged into a single string of nodes)");
    282292
    283293        return nodeList;
Note: See TracChangeset for help on using the changeset viewer.