source: josm/trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java@ 12828

Last change on this file since 12828 was 12828, checked in by Don-vip, 7 years ago

see #15229 - see #15182 - see #13036 - convert SplitWayAction to SplitWayCommand to remove dependence of DeleteCommand on actions package

  • Property svn:eol-style set to native
File size: 25.0 KB
RevLine 
[6380]1// License: GPL. For details, see LICENSE file.
[626]2package org.openstreetmap.josm.actions;
3
[2412]4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
[626]5import static org.openstreetmap.josm.tools.I18n.tr;
6import static org.openstreetmap.josm.tools.I18n.trn;
7
[8886]8import java.awt.Component;
[8897]9import java.awt.GridBagLayout;
[626]10import java.awt.event.ActionEvent;
11import java.awt.event.KeyEvent;
12import java.util.ArrayList;
13import java.util.Collection;
[5570]14import java.util.Collections;
[626]15import java.util.Iterator;
16import java.util.List;
[9245]17import java.util.concurrent.atomic.AtomicInteger;
[626]18
[8886]19import javax.swing.DefaultListCellRenderer;
20import javax.swing.JLabel;
21import javax.swing.JList;
[626]22import javax.swing.JOptionPane;
[8886]23import javax.swing.JPanel;
24import javax.swing.ListSelectionModel;
[626]25
26import org.openstreetmap.josm.Main;
27import org.openstreetmap.josm.command.Command;
[12828]28import org.openstreetmap.josm.command.SplitWayCommand;
[12663]29import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
[626]30import org.openstreetmap.josm.data.osm.Node;
31import org.openstreetmap.josm.data.osm.OsmPrimitive;
[2521]32import org.openstreetmap.josm.data.osm.PrimitiveId;
[626]33import org.openstreetmap.josm.data.osm.Relation;
34import org.openstreetmap.josm.data.osm.Way;
[8886]35import org.openstreetmap.josm.data.osm.WaySegment;
36import org.openstreetmap.josm.gui.ExtendedDialog;
[12630]37import org.openstreetmap.josm.gui.MainApplication;
38import org.openstreetmap.josm.gui.MapFrame;
[6130]39import org.openstreetmap.josm.gui.Notification;
[3152]40import org.openstreetmap.josm.gui.layer.OsmDataLayer;
[8897]41import org.openstreetmap.josm.tools.GBC;
[1084]42import org.openstreetmap.josm.tools.Shortcut;
[626]43
44/**
45 * Splits a way into multiple ways (all identical except for their node list).
[1023]46 *
[626]47 * Ways are just split at the selected nodes. The nodes remain in their
48 * original order. Selected nodes at the end of a way are ignored.
49 */
[1820]50public class SplitWayAction extends JosmAction {
[626]51
[5401]52 /**
53 * Represents the result of a {@link SplitWayAction}
54 * @see SplitWayAction#splitWay
55 * @see SplitWayAction#split
[12828]56 * @deprecated To be removed end of 2017. Use {@link SplitWayCommand} instead
[5401]57 */
[12828]58 @Deprecated
[2521]59 public static class SplitWayResult {
60 private final Command command;
61 private final List<? extends PrimitiveId> newSelection;
[8931]62 private final Way originalWay;
63 private final List<Way> newWays;
[2521]64
[5401]65 /**
[8540]66 * @param command The command to be performed to split the way (which is saved for later retrieval with {@link #getCommand})
67 * @param newSelection The new list of selected primitives ids (which is saved for later retrieval with {@link #getNewSelection})
68 * @param originalWay The original way being split (which is saved for later retrieval with {@link #getOriginalWay})
69 * @param newWays The resulting new ways (which is saved for later retrieval with {@link #getOriginalWay})
[5401]70 */
[3152]71 public SplitWayResult(Command command, List<? extends PrimitiveId> newSelection, Way originalWay, List<Way> newWays) {
[2521]72 this.command = command;
73 this.newSelection = newSelection;
[3152]74 this.originalWay = originalWay;
75 this.newWays = newWays;
[2521]76 }
77
[5401]78 /**
[12828]79 * @param command The command to be performed to split the way (which is saved for later retrieval with {@link #getCommand})
80 * @since 12828
81 */
82 protected SplitWayResult(SplitWayCommand command) {
83 this.command = command;
84 this.newSelection = command.getNewSelection();
85 this.originalWay = command.getOriginalWay();
86 this.newWays = command.getNewWays();
87 }
88
89 /**
[5401]90 * Replies the command to be performed to split the way
91 * @return The command to be performed to split the way
92 */
[2521]93 public Command getCommand() {
94 return command;
95 }
96
[5401]97 /**
98 * Replies the new list of selected primitives ids
99 * @return The new list of selected primitives ids
100 */
[2521]101 public List<? extends PrimitiveId> getNewSelection() {
102 return newSelection;
103 }
[3152]104
[5401]105 /**
106 * Replies the original way being split
107 * @return The original way being split
108 */
[3152]109 public Way getOriginalWay() {
110 return originalWay;
111 }
112
[5401]113 /**
114 * Replies the resulting new ways
115 * @return The resulting new ways
116 */
[3152]117 public List<Way> getNewWays() {
118 return newWays;
119 }
[2521]120 }
121
[1169]122 /**
123 * Create a new SplitWayAction.
124 */
125 public SplitWayAction() {
126 super(tr("Split Way"), "splitway", tr("Split a way at the selected node."),
[4982]127 Shortcut.registerShortcut("tools:splitway", tr("Tool: {0}", tr("Split Way")), KeyEvent.VK_P, Shortcut.DIRECT), true);
[2323]128 putValue("help", ht("/Action/SplitWay"));
[1169]129 }
[626]130
[1169]131 /**
132 * Called when the action is executed.
133 *
134 * This method performs an expensive check whether the selection clearly defines one
135 * of the split actions outlined above, and if yes, calls the splitWay method.
136 */
[6084]137 @Override
[1169]138 public void actionPerformed(ActionEvent e) {
[626]139
[9245]140 if (SegmentToKeepSelectionDialog.DISPLAY_COUNT.get() > 0) {
141 new Notification(tr("Cannot split since another split operation is already in progress"))
142 .setIcon(JOptionPane.WARNING_MESSAGE).show();
143 return;
144 }
145
[10382]146 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
[626]147
[3152]148 List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class);
149 List<Way> selectedWays = OsmPrimitive.getFilteredList(selection, Way.class);
[3392]150 List<Way> applicableWays = getApplicableWays(selectedWays, selectedNodes);
[3152]151
[3392]152 if (applicableWays == null) {
[6130]153 new Notification(
154 tr("The current selection cannot be used for splitting - no node is selected."))
155 .setIcon(JOptionPane.WARNING_MESSAGE)
156 .show();
[1169]157 return;
[3392]158 } else if (applicableWays.isEmpty()) {
[6130]159 new Notification(
160 tr("The selected nodes do not share the same way."))
161 .setIcon(JOptionPane.WARNING_MESSAGE)
162 .show();
[3392]163 return;
[1169]164 }
[626]165
[8276]166 // If several ways have been found, remove ways that doesn't have selected
167 // node in the middle
[5401]168 if (applicableWays.size() > 1) {
[8276]169 for (Iterator<Way> it = applicableWays.iterator(); it.hasNext();) {
170 Way w = it.next();
171 for (Node n : selectedNodes) {
172 if (!w.isInnerNode(n)) {
173 it.remove();
174 break;
[1169]175 }
176 }
[8276]177 }
[3392]178 }
[626]179
[3392]180 if (applicableWays.isEmpty()) {
[6130]181 new Notification(
[3392]182 trn("The selected node is not in the middle of any way.",
[6130]183 "The selected nodes are not in the middle of any way.",
184 selectedNodes.size()))
185 .setIcon(JOptionPane.WARNING_MESSAGE)
186 .show();
[3392]187 return;
188 } else if (applicableWays.size() > 1) {
[6130]189 new Notification(
[3392]190 trn("There is more than one way using the node you selected. Please select the way also.",
[6130]191 "There is more than one way using the nodes you selected. Please select the way also.",
192 selectedNodes.size()))
193 .setIcon(JOptionPane.WARNING_MESSAGE)
194 .show();
[3392]195 return;
196 }
[626]197
[3392]198 // Finally, applicableWays contains only one perfect way
[8886]199 final Way selectedWay = applicableWays.get(0);
[12828]200 final List<List<Node>> wayChunks = SplitWayCommand.buildSplitChunks(selectedWay, selectedNodes);
[3156]201 if (wayChunks != null) {
[10448]202 List<Relation> selectedRelations = OsmPrimitive.getFilteredList(selection, Relation.class);
[8886]203 final List<OsmPrimitive> sel = new ArrayList<>(selectedWays.size() + selectedRelations.size());
[3392]204 sel.addAll(selectedWays);
205 sel.addAll(selectedRelations);
[8886]206
207 final List<Way> newWays = createNewWaysFromChunks(selectedWay, wayChunks);
[12828]208 final Way wayToKeep = SplitWayCommand.Strategy.keepLongestChunk().determineWayToKeep(newWays);
[8886]209
[8978]210 if (ExpertToggleAction.isExpert() && !selectedWay.isNew()) {
[8886]211 final ExtendedDialog dialog = new SegmentToKeepSelectionDialog(selectedWay, newWays, wayToKeep, sel);
[8978]212 dialog.toggleEnable("way.split.segment-selection-dialog");
213 if (!dialog.toggleCheckState()) {
214 dialog.setModal(false);
215 dialog.showDialog();
216 return; // splitting is performed in SegmentToKeepSelectionDialog.buttonAction()
217 }
[8886]218 }
[10131]219 if (wayToKeep != null) {
[12828]220 doSplitWay(selectedWay, wayToKeep, newWays, sel);
[10131]221 }
[3156]222 }
[1169]223 }
[626]224
[8276]225 /**
[8886]226 * A dialog to query which way segment should reuse the history of the way to split.
227 */
228 static class SegmentToKeepSelectionDialog extends ExtendedDialog {
[9245]229 static final AtomicInteger DISPLAY_COUNT = new AtomicInteger();
[10254]230 final transient Way selectedWay;
231 final transient List<Way> newWays;
[8886]232 final JList<Way> list;
[10254]233 final transient List<OsmPrimitive> selection;
234 final transient Way wayToKeep;
[8886]235
236 SegmentToKeepSelectionDialog(Way selectedWay, List<Way> newWays, Way wayToKeep, List<OsmPrimitive> selection) {
237 super(Main.parent, tr("Which way segment should reuse the history of {0}?", selectedWay.getId()),
238 new String[]{tr("Ok"), tr("Cancel")}, true);
239
240 this.selectedWay = selectedWay;
241 this.newWays = newWays;
242 this.selection = selection;
[8988]243 this.wayToKeep = wayToKeep;
[8886]244 this.list = new JList<>(newWays.toArray(new Way[newWays.size()]));
[8988]245 configureList();
[8886]246
[12279]247 setButtonIcons("ok", "cancel");
[8897]248 final JPanel pane = new JPanel(new GridBagLayout());
249 pane.add(new JLabel(getTitle()), GBC.eol().fill(GBC.HORIZONTAL));
250 pane.add(list, GBC.eop().fill(GBC.HORIZONTAL));
[8886]251 setContent(pane);
[9245]252 setDefaultCloseOperation(HIDE_ON_CLOSE);
[8886]253 }
254
[8978]255 private void configureList() {
[8886]256 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
[10601]257 list.addListSelectionListener(e -> {
258 final Way selected = list.getSelectedValue();
[12630]259 if (selected != null && MainApplication.isDisplayingMapView() && selected.getNodesCount() > 1) {
[10601]260 final Collection<WaySegment> segments = new ArrayList<>(selected.getNodesCount() - 1);
261 final Iterator<Node> it = selected.getNodes().iterator();
262 Node previousNode = it.next();
263 while (it.hasNext()) {
264 final Node node = it.next();
265 segments.add(WaySegment.forNodePair(selectedWay, previousNode, node));
266 previousNode = node;
[8886]267 }
[10601]268 setHighlightedWaySegments(segments);
[8886]269 }
270 });
[11343]271 list.setCellRenderer(new SegmentListCellRenderer());
[8886]272 }
273
274 protected void setHighlightedWaySegments(Collection<WaySegment> segments) {
275 selectedWay.getDataSet().setHighlightedWaySegments(segments);
[12630]276 MainApplication.getMap().mapView.repaint();
[8886]277 }
278
279 @Override
280 public void setVisible(boolean visible) {
281 super.setVisible(visible);
282 if (visible) {
[9245]283 DISPLAY_COUNT.incrementAndGet();
[8988]284 list.setSelectedValue(wayToKeep, true);
[8886]285 } else {
286 setHighlightedWaySegments(Collections.<WaySegment>emptyList());
[9245]287 DISPLAY_COUNT.decrementAndGet();
[8886]288 }
289 }
290
291 @Override
292 protected void buttonAction(int buttonIndex, ActionEvent evt) {
293 super.buttonAction(buttonIndex, evt);
[8978]294 toggleSaveState(); // necessary since #showDialog() does not handle it due to the non-modal dialog
[8886]295 if (getValue() == 1) {
[12828]296 doSplitWay(selectedWay, list.getSelectedValue(), newWays, selection);
[8886]297 }
298 }
299 }
300
[11343]301 static class SegmentListCellRenderer extends DefaultListCellRenderer {
302 @Override
303 public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
304 final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
305 final String name = DefaultNameFormatter.getInstance().format((Way) value);
306 // get rid of id from DefaultNameFormatter.decorateNameWithId()
307 final String nameWithoutId = name
308 .replace(tr(" [id: {0}]", ((Way) value).getId()), "")
309 .replace(tr(" [id: {0}]", ((Way) value).getUniqueId()), "");
310 ((JLabel) c).setText(tr("Segment {0}: {1}", index + 1, nameWithoutId));
311 return c;
312 }
313 }
314
[8886]315 /**
[8955]316 * Determines which way chunk should reuse the old id and its history
317 *
318 * @since 8954
[10599]319 * @since 10599 (functional interface)
[12828]320 * @deprecated to be removed end of 2017. Use {@link org.openstreetmap.josm.command.SplitWayCommand.Strategy} instead
[8886]321 */
[12828]322 @Deprecated
[10599]323 @FunctionalInterface
324 public interface Strategy {
[8955]325
326 /**
327 * Determines which way chunk should reuse the old id and its history.
328 *
329 * @param wayChunks the way chunks
330 * @return the way to keep
331 */
[10599]332 Way determineWayToKeep(Iterable<Way> wayChunks);
[8955]333
334 /**
335 * Returns a strategy which selects the way chunk with the highest node count to keep.
[9230]336 * @return strategy which selects the way chunk with the highest node count to keep
[8955]337 */
[10599]338 static Strategy keepLongestChunk() {
[12828]339 return SplitWayCommand.Strategy.keepLongestChunk()::determineWayToKeep;
[8886]340 }
[8955]341
342 /**
343 * Returns a strategy which selects the first way chunk.
[9230]344 * @return strategy which selects the first way chunk
[8955]345 */
[10599]346 static Strategy keepFirstChunk() {
[12828]347 return SplitWayCommand.Strategy.keepFirstChunk()::determineWayToKeep;
[8955]348 }
[8886]349 }
350
351 /**
352 * Determine which ways to split.
[8276]353 * @param selectedWays List of user selected ways.
354 * @param selectedNodes List of user selected nodes.
355 * @return List of ways to split
356 */
[10074]357 static List<Way> getApplicableWays(List<Way> selectedWays, List<Node> selectedNodes) {
[3392]358 if (selectedNodes.isEmpty())
359 return null;
360
[10074]361 // Special case - one of the selected ways touches (not cross) way that we want to split
[5570]362 if (selectedNodes.size() == 1) {
363 Node n = selectedNodes.get(0);
[12031]364 List<Way> referredWays = n.getParentWays();
[5570]365 Way inTheMiddle = null;
[10775]366 for (Way w: referredWays) {
[8276]367 // Need to look at all nodes see #11184 for a case where node n is
368 // firstNode, lastNode and also in the middle
369 if (selectedWays.contains(w) && w.isInnerNode(n)) {
[5570]370 if (inTheMiddle == null) {
371 inTheMiddle = w;
372 } else {
373 inTheMiddle = null;
374 break;
375 }
376 }
377 }
[8276]378 if (inTheMiddle != null)
[5570]379 return Collections.singletonList(inTheMiddle);
380 }
381
[3392]382 // List of ways shared by all nodes
[10074]383 return UnJoinNodeWayAction.getApplicableWays(selectedWays, selectedNodes);
[1169]384 }
[626]385
[1169]386 /**
[3152]387 * Splits the nodes of {@code wayToSplit} into a list of node sequences
388 * which are separated at the nodes in {@code splitPoints}.
[3156]389 *
[3152]390 * This method displays warning messages if {@code wayToSplit} and/or
391 * {@code splitPoints} aren't consistent.
[3156]392 *
[3152]393 * Returns null, if building the split chunks fails.
[3156]394 *
[3152]395 * @param wayToSplit the way to split. Must not be null.
396 * @param splitPoints the nodes where the way is split. Must not be null.
397 * @return the list of chunks
[12828]398 * @deprecated To be removed end of 2017. Use {@link SplitWayCommand#buildSplitChunks} instead
[1169]399 */
[12828]400 @Deprecated
[8510]401 public static List<List<Node>> buildSplitChunks(Way wayToSplit, List<Node> splitPoints) {
[12828]402 return SplitWayCommand.buildSplitChunks(wayToSplit, splitPoints);
[2521]403 }
404
[3152]405 /**
[8886]406 * Creates new way objects for the way chunks and transfers the keys from the original way.
407 * @param way the original way whose keys are transferred
408 * @param wayChunks the way chunks
409 * @return the new way objects
[12828]410 * @deprecated To be removed end of 2017. Use {@link SplitWayCommand#createNewWaysFromChunks} instead
[8886]411 */
[12828]412 @Deprecated
[8886]413 protected static List<Way> createNewWaysFromChunks(Way way, Iterable<List<Node>> wayChunks) {
[12828]414 return SplitWayCommand.createNewWaysFromChunks(way, wayChunks);
[8886]415 }
416
417 /**
[5401]418 * Splits the way {@code way} into chunks of {@code wayChunks} and replies
419 * the result of this process in an instance of {@link SplitWayResult}.
420 *
421 * Note that changes are not applied to the data yet. You have to
422 * submit the command in {@link SplitWayResult#getCommand()} first,
423 * i.e. {@code Main.main.undoredo.add(result.getCommand())}.
424 *
[12287]425 * @param layer the layer which the way belongs to.
[5401]426 * @param way the way to split. Must not be null.
427 * @param wayChunks the list of way chunks into the way is split. Must not be null.
428 * @param selection The list of currently selected primitives
429 * @return the result from the split operation
[12718]430 * @deprecated to be removed end of 2017. Use {@link #splitWay(Way, List, Collection)} instead
[3152]431 */
[12718]432 @Deprecated
[8540]433 public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks,
434 Collection<? extends OsmPrimitive> selection) {
[12718]435 return splitWay(way, wayChunks, selection);
[8955]436 }
437
438 /**
439 * Splits the way {@code way} into chunks of {@code wayChunks} and replies
440 * the result of this process in an instance of {@link SplitWayResult}.
[12718]441 *
442 * Note that changes are not applied to the data yet. You have to
443 * submit the command in {@link SplitWayResult#getCommand()} first,
444 * i.e. {@code Main.main.undoredo.add(result.getCommand())}.
445 *
446 * @param way the way to split. Must not be null.
447 * @param wayChunks the list of way chunks into the way is split. Must not be null.
448 * @param selection The list of currently selected primitives
449 * @return the result from the split operation
450 * @since 12718
[12828]451 * @deprecated to be removed end of 2017. Use {@link #splitWay(Way, List, Collection)} instead
[12718]452 */
[12828]453 @Deprecated
[12718]454 public static SplitWayResult splitWay(Way way, List<List<Node>> wayChunks,
455 Collection<? extends OsmPrimitive> selection) {
456 return splitWay(way, wayChunks, selection, Strategy.keepLongestChunk());
457 }
458
459 /**
460 * Splits the way {@code way} into chunks of {@code wayChunks} and replies
461 * the result of this process in an instance of {@link SplitWayResult}.
[8955]462 * The {@link org.openstreetmap.josm.actions.SplitWayAction.Strategy} is used to determine which
463 * way chunk should reuse the old id and its history.
464 *
465 * Note that changes are not applied to the data yet. You have to
466 * submit the command in {@link SplitWayResult#getCommand()} first,
467 * i.e. {@code Main.main.undoredo.add(result.getCommand())}.
468 *
[12287]469 * @param layer the layer which the way belongs to.
[8955]470 * @param way the way to split. Must not be null.
471 * @param wayChunks the list of way chunks into the way is split. Must not be null.
472 * @param selection The list of currently selected primitives
473 * @param splitStrategy The strategy used to determine which way chunk should reuse the old id and its history
474 * @return the result from the split operation
475 * @since 8954
[12718]476 * @deprecated to be removed end of 2017. Use {@link #splitWay(Way, List, Collection, Strategy)} instead
[8955]477 */
[12718]478 @Deprecated
[8955]479 public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks,
480 Collection<? extends OsmPrimitive> selection, Strategy splitStrategy) {
[12718]481 return splitWay(way, wayChunks, selection, splitStrategy);
482 }
483
484 /**
485 * Splits the way {@code way} into chunks of {@code wayChunks} and replies
486 * the result of this process in an instance of {@link SplitWayResult}.
487 * The {@link org.openstreetmap.josm.actions.SplitWayAction.Strategy} is used to determine which
488 * way chunk should reuse the old id and its history.
489 *
490 * Note that changes are not applied to the data yet. You have to
491 * submit the command in {@link SplitWayResult#getCommand()} first,
492 * i.e. {@code Main.main.undoredo.add(result.getCommand())}.
493 *
494 * @param way the way to split. Must not be null.
495 * @param wayChunks the list of way chunks into the way is split. Must not be null.
496 * @param selection The list of currently selected primitives
497 * @param splitStrategy The strategy used to determine which way chunk should reuse the old id and its history
498 * @return the result from the split operation
499 * @since 12718
[12828]500 * @deprecated to be removed end of 2017. Use {@link SplitWayCommand#splitWay} instead
[12718]501 */
[12828]502 @Deprecated
[12718]503 public static SplitWayResult splitWay(Way way, List<List<Node>> wayChunks,
504 Collection<? extends OsmPrimitive> selection, Strategy splitStrategy) {
[12828]505 SplitWayCommand cmd = SplitWayCommand.splitWay(way, wayChunks, selection, x -> splitStrategy.determineWayToKeep(x));
506 return cmd != null ? new SplitWayResult(cmd) : null;
[8886]507 }
508
[12828]509 static void doSplitWay(Way way, Way wayToKeep, List<Way> newWays, List<OsmPrimitive> newSelection) {
[12630]510 final MapFrame map = MainApplication.getMap();
511 final boolean isMapModeDraw = map != null && map.mapMode == map.mapModeDraw;
[12828]512 final SplitWayCommand result = SplitWayCommand.doSplitWay(way, wayToKeep, newWays, !isMapModeDraw ? newSelection : null);
513 MainApplication.undoRedo.add(result);
514 List<? extends PrimitiveId> newSel = result.getNewSelection();
515 if (newSel != null && !newSel.isEmpty()) {
516 MainApplication.getLayerManager().getEditDataSet().setSelected(newSel);
[3392]517 }
[1169]518 }
[626]519
[3152]520 /**
521 * Splits the way {@code way} at the nodes in {@code atNodes} and replies
[5266]522 * the result of this process in an instance of {@link SplitWayResult}.
[3156]523 *
[3152]524 * Note that changes are not applied to the data yet. You have to
[5266]525 * submit the command in {@link SplitWayResult#getCommand()} first,
[3152]526 * i.e. {@code Main.main.undoredo.add(result.getCommand())}.
[3156]527 *
[3152]528 * Replies null if the way couldn't be split at the given nodes.
[3156]529 *
[12287]530 * @param layer the layer which the way belongs to.
[3152]531 * @param way the way to split. Must not be null.
532 * @param atNodes the list of nodes where the way is split. Must not be null.
[5401]533 * @param selection The list of currently selected primitives
[3152]534 * @return the result from the split operation
[12718]535 * @deprecated to be removed end of 2017. Use {@link #split(Way, List, Collection) instead}
[3152]536 */
[12718]537 @Deprecated
[6889]538 public static SplitWayResult split(OsmDataLayer layer, Way way, List<Node> atNodes, Collection<? extends OsmPrimitive> selection) {
[12718]539 return split(way, atNodes, selection);
540 }
541
542 /**
543 * Splits the way {@code way} at the nodes in {@code atNodes} and replies
544 * the result of this process in an instance of {@link SplitWayResult}.
545 *
546 * Note that changes are not applied to the data yet. You have to
547 * submit the command in {@link SplitWayResult#getCommand()} first,
548 * i.e. {@code Main.main.undoredo.add(result.getCommand())}.
549 *
550 * Replies null if the way couldn't be split at the given nodes.
551 *
552 * @param way the way to split. Must not be null.
553 * @param atNodes the list of nodes where the way is split. Must not be null.
554 * @param selection The list of currently selected primitives
555 * @return the result from the split operation
556 * @since 12718
[12828]557 * @deprecated to be removed end of 2017. Use {@link #splitWay(Way, List, Collection)} instead
[12718]558 */
[12828]559 @Deprecated
[12718]560 public static SplitWayResult split(Way way, List<Node> atNodes, Collection<? extends OsmPrimitive> selection) {
[3152]561 List<List<Node>> chunks = buildSplitChunks(way, atNodes);
[12718]562 return chunks != null ? splitWay(way, chunks, selection) : null;
[3152]563 }
564
[1820]565 @Override
566 protected void updateEnabledState() {
[10548]567 updateEnabledStateOnCurrentSelection();
[2256]568 }
569
570 @Override
571 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
572 if (selection == null) {
573 setEnabled(false);
[1820]574 return;
575 }
[3392]576 for (OsmPrimitive primitive: selection) {
577 if (primitive instanceof Node) {
578 setEnabled(true); // Selection still can be wrong, but let SplitWayAction process and tell user what's wrong
579 return;
580 }
581 }
582 setEnabled(false);
[1169]583 }
[626]584}
Note: See TracBrowser for help on using the repository browser.