Package org.openstreetmap.josm.actions
Class UnGlueAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.UnGlueAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
,Destroyable
public class UnGlueAction extends JosmAction
Duplicate nodes that are used by multiple ways or tagged nodes used by a single way or nodes which referenced more than once by a single way. This is the opposite of the MergeNodesAction.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter
-
-
Field Summary
Fields Modifier and Type Field Description private Node
selectedNode
private java.util.Set<Node>
selectedNodes
private Way
selectedWay
-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Constructor Description UnGlueAction()
Create a new UnGlueAction.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
Called when the action is executed.private boolean
addCheckedChangeNodesCmd(java.util.List<Command> cmds, Way w, java.util.List<Node> nodes)
protected java.util.Set<Relation>
calcAffectedRelations(java.util.Collection<Way> ways)
protected void
checkAndConfirmOutlyingUnglue()
private boolean
checkSelectionOneNodeAtMostOneWay(java.util.Collection<? extends OsmPrimitive> selection)
Checks if the selection consists of something we can work with.private boolean
checkSelectionOneWayAnyNodes(java.util.Collection<? extends OsmPrimitive> selection)
Checks if the selection consists of something we can work with.private void
cleanup()
private static Node
cloneNode(Node originalNode, java.util.List<Command> cmds)
private void
execCommands(java.util.List<Command> cmds, java.util.List<Node> newNodes)
Add commands to undo-redo system.private static boolean
isRelationAffected(Relation r, java.util.Set<Node> affectedNodes, java.util.Collection<Way> ways)
private static java.util.List<Node>
modifyWay(Node originalNode, Way w, java.util.List<Command> cmds, java.util.List<Node> newNodes)
dupe the given node of the given way assume that originalNode is in the way the new node will be put into the parameter newNodes. the add-node command will be put into the parameter cmds. the changed way will be returned and must be put into cmds by the caller!protected void
notifyWayPartOfRelation(java.util.Collection<Way> ways)
protected void
unglue()
private boolean
unglueClosedOrSelfCrossingWay(Way way, PropertiesMembershipChoiceDialog dialog)
Duplicates a node used several times by the same way.private void
unglueOneNodeAtMostOneWay(Way way, PropertiesMembershipChoiceDialog dialog)
Assumes there is one tagged Node stored in selectedNode that it will try to unglue.private void
unglueOneWayAnyNodes()
dupe all nodes that are selected, and put the copies on the selected wayprivate void
unglueWays()
dupe a single node into as many nodes as there are ways using it, OR dupe a single node once, and put the copy on the selected way(package private) static void
update(PropertiesMembershipChoiceDialog dialog, Node existingNode, java.util.List<Node> newNodes, java.util.List<Command> cmds)
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.private static void
updateMemberships(PropertiesMembershipChoiceDialog.ExistingBothNew memberships, Node originalNode, java.util.List<Node> newNodes, java.util.List<Command> cmds)
put all newNodes into the same relation(s) that originalNode is inprivate static void
updateProperties(PropertiesMembershipChoiceDialog.ExistingBothNew tags, Node existingNode, java.lang.Iterable<Node> newNodes, java.util.List<Command> cmds)
-
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
buildActiveLayerChangeAdapter, buildLayerChangeAdapter, checkAndConfirmOutlyingOperation, destroy, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setToolbarId, setTooltip, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFuture
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
-
-
-
Field Detail
-
selectedNode
private transient Node selectedNode
-
selectedWay
private transient Way selectedWay
-
selectedNodes
private transient java.util.Set<Node> selectedNodes
-
-
Constructor Detail
-
UnGlueAction
public UnGlueAction()
Create a new UnGlueAction.
-
-
Method Detail
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Called when the action is executed. This method does some checking on the selection and calls the matching unGlueWay method.
-
unglue
protected void unglue() throws UserCancelException
- Throws:
UserCancelException
-
cleanup
private void cleanup()
-
update
static void update(PropertiesMembershipChoiceDialog dialog, Node existingNode, java.util.List<Node> newNodes, java.util.List<Command> cmds)
-
updateProperties
private static void updateProperties(PropertiesMembershipChoiceDialog.ExistingBothNew tags, Node existingNode, java.lang.Iterable<Node> newNodes, java.util.List<Command> cmds)
-
unglueOneNodeAtMostOneWay
private void unglueOneNodeAtMostOneWay(Way way, PropertiesMembershipChoiceDialog dialog)
Assumes there is one tagged Node stored in selectedNode that it will try to unglue. (i.e. copy node and remove all tags from the old one.)- Parameters:
way
- way to modifydialog
- the user dialog
-
checkSelectionOneNodeAtMostOneWay
private boolean checkSelectionOneNodeAtMostOneWay(java.util.Collection<? extends OsmPrimitive> selection)
Checks if the selection consists of something we can work with. Checks only if the number and type of items selected looks good. If this method returns "true", selectedNode will be set, selectedWay might be set Returns true if either one node is selected or one node and one way are selected and the node is part of the way. The way will be put into the object variable "selectedWay", the node into "selectedNode".- Parameters:
selection
- selected primitives- Returns:
- true if either one node is selected or one node and one way are selected and the node is part of the way
-
checkSelectionOneWayAnyNodes
private boolean checkSelectionOneWayAnyNodes(java.util.Collection<? extends OsmPrimitive> selection)
Checks if the selection consists of something we can work with. Checks only if the number and type of items selected looks good. Returns true if one way and any number of nodes that are part of that way are selected. Note: "any" can be none, then all nodes of the way are used. The way will be put into the object variable "selectedWay", the nodes into "selectedNodes".- Parameters:
selection
- selected primitives- Returns:
- true if one way and any number of nodes that are part of that way are selected
-
modifyWay
private static java.util.List<Node> modifyWay(Node originalNode, Way w, java.util.List<Command> cmds, java.util.List<Node> newNodes)
dupe the given node of the given way assume that originalNode is in the way- the new node will be put into the parameter newNodes.
- the add-node command will be put into the parameter cmds.
- the changed way will be returned and must be put into cmds by the caller!
- Parameters:
originalNode
- original node to duplicatew
- parent waycmds
- List of commands that will contain the new "add node" commandnewNodes
- List of nodes that will contain the new node- Returns:
- The modified list of way nodes. Change command must be handled by the caller
-
updateMemberships
private static void updateMemberships(PropertiesMembershipChoiceDialog.ExistingBothNew memberships, Node originalNode, java.util.List<Node> newNodes, java.util.List<Command> cmds)
put all newNodes into the same relation(s) that originalNode is in- Parameters:
memberships
- where the memberships should be placesoriginalNode
- original node to duplicatecmds
- List of commands that will contain the new "change relation" commandsnewNodes
- List of nodes that contain the new node
-
unglueWays
private void unglueWays() throws UserCancelException
dupe a single node into as many nodes as there are ways using it, OR dupe a single node once, and put the copy on the selected way- Throws:
UserCancelException
- if user cancels choice
-
execCommands
private void execCommands(java.util.List<Command> cmds, java.util.List<Node> newNodes)
Add commands to undo-redo system.- Parameters:
cmds
- Commands to executenewNodes
- New created nodes by this set of command
-
unglueClosedOrSelfCrossingWay
private boolean unglueClosedOrSelfCrossingWay(Way way, PropertiesMembershipChoiceDialog dialog)
Duplicates a node used several times by the same way. See #9896. First occurrence is kept. A closed way will be "opened" when the closing node is unglued.- Parameters:
way
- way to modifydialog
- user dialog, might be null- Returns:
- true if action is OK false if there is nothing to do
-
unglueOneWayAnyNodes
private void unglueOneWayAnyNodes() throws UserCancelException
dupe all nodes that are selected, and put the copies on the selected way- Throws:
UserCancelException
- if user cancels choice
-
addCheckedChangeNodesCmd
private boolean addCheckedChangeNodesCmd(java.util.List<Command> cmds, Way w, java.util.List<Node> nodes)
-
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. SeeJosmAction.updateEnabledState(Collection)
to respond to changes in the collection of selected primitives. Default behavior is empty.- Overrides:
updateEnabledState
in classJosmAction
- See Also:
JosmAction.updateEnabledState(Collection)
,JosmAction.initEnabledState()
,JosmAction.listenToLayerChange()
-
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 classJosmAction
- Parameters:
selection
- the collection of selected primitives; may be empty, but not null- See Also:
JosmAction.updateEnabledState()
,JosmAction.initEnabledState()
,JosmAction.listenToSelectionChange()
-
checkAndConfirmOutlyingUnglue
protected void checkAndConfirmOutlyingUnglue() throws UserCancelException
- Throws:
UserCancelException
-
notifyWayPartOfRelation
protected void notifyWayPartOfRelation(java.util.Collection<Way> ways)
-
calcAffectedRelations
protected java.util.Set<Relation> calcAffectedRelations(java.util.Collection<Way> ways)
-
isRelationAffected
private static boolean isRelationAffected(Relation r, java.util.Set<Node> affectedNodes, java.util.Collection<Way> ways)
-
-