Changeset 1814 in josm for trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
- Timestamp:
- 2009-07-19T19:04:49+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r1621 r1814 52 52 public CombineWayAction() { 53 53 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); 55 55 DataSet.selListeners.add(this); 56 56 } 57 57 58 58 public void actionPerformed(ActionEvent event) { 59 Collection<OsmPrimitive> selection = Main.ds.getSelected();59 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 60 60 LinkedList<Way> selectedWays = new LinkedList<Way>(); 61 61 62 62 for (OsmPrimitive osm : selection) 63 if (osm instanceof Way) 63 if (osm instanceof Way) { 64 64 selectedWays.add((Way)osm); 65 } 65 66 66 67 if (selectedWays.size() < 2) { … … 82 83 new HashMap<Pair<Relation,String>, HashSet<Way>>(); 83 84 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 } 86 89 for (RelationMember rm : r.members) { 87 90 if (rm.member instanceof Way) { … … 112 115 tr("Combine ways with different memberships?"), 113 116 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 } 118 123 119 124 return; … … 125 130 for (Way w : selectedWays) { 126 131 for (Entry<String,String> e : w.entrySet()) { 127 if (!props.containsKey(e.getKey())) 132 if (!props.containsKey(e.getKey())) { 128 133 props.put(e.getKey(), new TreeSet<String>()); 134 } 129 135 props.get(e.getKey()).add(e.getValue()); 130 136 } … … 139 145 if (secondTry instanceof List) { 140 146 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(); 146 152 if (option != 1) return; 147 153 nodeList = (List<Node>) secondTry; … … 160 166 for (Way w : selectedWays) { 161 167 modifyWay = w; 162 if (w.id != 0) break; 168 if (w.id != 0) { 169 break; 170 } 163 171 } 164 172 Way newWay = new Way(modifyWay); … … 188 196 if (!components.isEmpty()) { 189 197 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(); 194 202 if (answer != 1) return; 195 203 196 for (Entry<String, JComboBox> e : components.entrySet()) 204 for (Entry<String, JComboBox> e : components.entrySet()) { 197 205 newWay.put(e.getKey(), e.getValue().getEditor().getItem().toString()); 206 } 198 207 } 199 208 … … 224 233 } 225 234 Main.main.undoRedo.add(new SequenceCommand(tr("Combine {0} ways", selectedWays.size()), cmds)); 226 Main.ds.setSelected(modifyWay);235 getCurrentDataSet().setSelected(modifyWay); 227 236 } 228 237 … … 242 251 243 252 HashSet<Pair<Node,Node>> chunkSet = new HashSet<Pair<Node,Node>>(); 244 for (Way w : ways) 253 for (Way w : ways) { 245 254 chunkSet.addAll(w.getNodePairs(ignoreDirection)); 255 } 246 256 247 257 LinkedList<Pair<Node,Node>> chunks = new LinkedList<Pair<Node,Node>>(chunkSet); 248 258 249 if (chunks.isEmpty()) {259 if (chunks.isEmpty()) 250 260 return tr("All the ways were empty"); 251 }252 261 253 262 List<Node> nodeList = Pair.toArrayList(chunks.poll()); … … 273 282 break; 274 283 } 275 if (!foundChunk) break; 276 } 277 278 if (!chunks.isEmpty()) { 284 if (!foundChunk) { 285 break; 286 } 287 } 288 289 if (!chunks.isEmpty()) 279 290 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)"); 282 292 283 293 return nodeList;
Note:
See TracChangeset
for help on using the changeset viewer.