Package org.openstreetmap.josm.actions
Class DistributeAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.DistributeAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
,Destroyable
public final class DistributeAction extends JosmAction
Distributes the selected nodes to equal distances along a line.- 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 inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Constructor Description DistributeAction()
Constructs a newDistributeAction
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
Perform action.private static boolean
checkDistributeNodes(java.util.Collection<Way> ways, java.util.Collection<Node> nodes)
Test if nodes oriented algorithm applies to the selection.private static boolean
checkDistributeWay(java.util.Collection<Way> ways, java.util.Collection<Node> nodes)
Test if one way, no self-crossing, is selected with at most two of its nodes.private static java.util.Collection<Command>
distributeNodes(java.util.Collection<Node> nodes)
Distribute nodes when only nodes are selected.private static java.util.Collection<Command>
distributeWay(java.util.Collection<Way> ways, java.util.Collection<Node> nodes)
Distribute nodes contained by a way, keeping nodes order.private static java.util.Set<Node>
removeNodesWithoutCoordinates(java.util.Collection<Node> col)
Remove nodes without known coordinates from a collection.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
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
-
-
-
-
Constructor Detail
-
DistributeAction
public DistributeAction()
Constructs a newDistributeAction
.
-
-
Method Detail
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Perform action. Select method according to user selection. Case 1: One Way (no self-crossing) and at most 2 nodes contains by this way: Distribute nodes keeping order along the way Case 2: Other Distribute nodes
-
checkDistributeWay
private static boolean checkDistributeWay(java.util.Collection<Way> ways, java.util.Collection<Node> nodes)
Test if one way, no self-crossing, is selected with at most two of its nodes.- Parameters:
ways
- Selected waysnodes
- Selected nodes- Returns:
- true in this case
-
distributeWay
private static java.util.Collection<Command> distributeWay(java.util.Collection<Way> ways, java.util.Collection<Node> nodes)
Distribute nodes contained by a way, keeping nodes order. If one or two nodes are selected, keep these nodes in place.- Parameters:
ways
- Selected ways, must be collection of size 1.nodes
- Selected nodes, at most two nodes.- Returns:
- Collection of command to be executed.
-
checkDistributeNodes
private static boolean checkDistributeNodes(java.util.Collection<Way> ways, java.util.Collection<Node> nodes)
Test if nodes oriented algorithm applies to the selection.- Parameters:
ways
- Selected waysnodes
- Selected nodes- Returns:
- true in this case
-
distributeNodes
private static java.util.Collection<Command> distributeNodes(java.util.Collection<Node> nodes)
Distribute nodes when only nodes are selected. The general algorithm here is to find the two selected nodes that are furthest apart, and then to distribute all other selected nodes along the straight line between these nodes.- Parameters:
nodes
- nodes to distribute- Returns:
- Commands to execute to perform action
- Throws:
java.lang.IllegalArgumentException
- if nodes is empty
-
removeNodesWithoutCoordinates
private static java.util.Set<Node> removeNodesWithoutCoordinates(java.util.Collection<Node> col)
Remove nodes without known coordinates from a collection.- Parameters:
col
- Collection of nodes to check- Returns:
- Set of nodes without coordinates
-
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()
-
-