org.openstreetmap.josm.actions
Class SplitWayAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.openstreetmap.josm.actions.JosmAction
          extended by org.openstreetmap.josm.actions.SplitWayAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action, Destroyable

public class SplitWayAction
extends JosmAction

Splits a way into multiple ways (all identical except for their node list). Ways are just split at the selected nodes. The nodes remain in their original order. Selected nodes at the end of a way are ignored.

See Also:
Serialized Form

Nested Class Summary
static class SplitWayAction.SplitWayResult
          Represents the result of a SplitWayAction
 
Field Summary
 
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
SplitWayAction()
          Create a new SplitWayAction.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Called when the action is executed.
static java.util.List<java.util.List<Node>> buildSplitChunks(Way wayToSplit, java.util.List<Node> splitPoints)
          Splits the nodes of wayToSplit into a list of node sequences which are separated at the nodes in splitPoints.
private  java.util.List<Way> getApplicableWays(java.util.List<Way> selectedWays, java.util.List<Node> selectedNodes)
           
static SplitWayAction.SplitWayResult split(OsmDataLayer layer, Way way, java.util.List<Node> atNodes, java.util.Collection<? extends OsmPrimitive> selection)
          Splits the way way at the nodes in atNodes and replies the result of this process in an instance of SplitWayAction.SplitWayResult.
static SplitWayAction.SplitWayResult splitWay(OsmDataLayer layer, Way way, java.util.List<java.util.List<Node>> wayChunks, java.util.Collection<? extends OsmPrimitive> selection)
          Splits the way way into chunks of wayChunks and replies the result of this process in an instance of SplitWayAction.SplitWayResult.
protected  void updateEnabledState()
          Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.
protected  void updateEnabledState(java.util.Collection<? extends OsmPrimitive> selection)
          Override in subclasses to update the enabled state of the action if the collection of selected primitives changes.
 
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
destroy, getCurrentDataSet, getEditLayer, getShortcut, initEnabledState, installAdapters, setTooltip
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SplitWayAction

public SplitWayAction()
Create a new SplitWayAction.

Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Called when the action is executed. This method performs an expensive check whether the selection clearly defines one of the split actions outlined above, and if yes, calls the splitWay method.


getApplicableWays

private java.util.List<Way> getApplicableWays(java.util.List<Way> selectedWays,
                                              java.util.List<Node> selectedNodes)

buildSplitChunks

public static java.util.List<java.util.List<Node>> buildSplitChunks(Way wayToSplit,
                                                                    java.util.List<Node> splitPoints)
Splits the nodes of wayToSplit into a list of node sequences which are separated at the nodes in splitPoints. This method displays warning messages if wayToSplit and/or splitPoints aren't consistent. Returns null, if building the split chunks fails.

Parameters:
wayToSplit - the way to split. Must not be null.
splitPoints - the nodes where the way is split. Must not be null.
Returns:
the list of chunks

splitWay

public static SplitWayAction.SplitWayResult splitWay(OsmDataLayer layer,
                                                     Way way,
                                                     java.util.List<java.util.List<Node>> wayChunks,
                                                     java.util.Collection<? extends OsmPrimitive> selection)
Splits the way way into chunks of wayChunks and replies the result of this process in an instance of SplitWayAction.SplitWayResult. Note that changes are not applied to the data yet. You have to submit the command in SplitWayAction.SplitWayResult.getCommand() first, i.e. Main.main.undoredo.add(result.getCommand()).

Parameters:
layer - the layer which the way belongs to. Must not be null.
way - the way to split. Must not be null.
wayChunks - the list of way chunks into the way is split. Must not be null.
selection - The list of currently selected primitives
Returns:
the result from the split operation

split

public static SplitWayAction.SplitWayResult split(OsmDataLayer layer,
                                                  Way way,
                                                  java.util.List<Node> atNodes,
                                                  java.util.Collection<? extends OsmPrimitive> selection)
Splits the way way at the nodes in atNodes and replies the result of this process in an instance of SplitWayAction.SplitWayResult. Note that changes are not applied to the data yet. You have to submit the command in SplitWayAction.SplitWayResult.getCommand() first, i.e. Main.main.undoredo.add(result.getCommand()). Replies null if the way couldn't be split at the given nodes.

Parameters:
layer - the layer which the way belongs to. Must not be null.
way - the way to split. Must not be null.
atNodes - the list of nodes where the way is split. Must not be null.
selection - The list of currently selected primitives
Returns:
the result from the split operation

updateEnabledState

protected void updateEnabledState()
Description copied from class: JosmAction
Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e. when a layer is removed or added. See JosmAction.updateEnabledState(Collection) to respond to changes in the collection of selected primitives. Default behavior is empty.

Overrides:
updateEnabledState in class JosmAction
See Also:
JosmAction.updateEnabledState(Collection), JosmAction.initEnabledState()

updateEnabledState

protected void updateEnabledState(java.util.Collection<? extends OsmPrimitive> selection)
Description copied from class: JosmAction
Override in subclasses to update the enabled state of the action if the collection of selected primitives changes. This method is called with the new selection.

Overrides:
updateEnabledState in class JosmAction
Parameters:
selection - the collection of selected primitives; may be empty, but not null
See Also:
JosmAction.updateEnabledState(), JosmAction.initEnabledState()


JOSM