Package org.openstreetmap.josm.actions
Class AlignInLineAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.AlignInLineAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
,Destroyable
public final class AlignInLineAction extends JosmAction
Aligns all selected nodes into a straight line (useful for roads that should be straight, but have side roads and therefore need multiple nodes)Case 1: 1 or 2 ways selected and no nodes selected: align nodes of ways taking care of intersection. Case 2: Single node selected and no ways selected: align this node relative to all referrer ways (2 at most). Case 3: Single node and ways selected: align this node relative to selected ways. Case 4.1: Only nodes selected, part of a non-closed way: align these nodes on the line passing through the extremity nodes (most distant in the way sequence). See https://josm.openstreetmap.de/ticket/9605#comment:3 Case 4.2: Only nodes selected, part of a closed way: align these nodes on the line passing through the most distant nodes. Case 4.3: Only nodes selected, part of multiple ways: align these nodes on the line passing through the most distant nodes.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
AlignInLineAction.InvalidSelection
InvalidSelection exception has to be raised when action can't be performed(package private) static class
AlignInLineAction.Line
Class that represent a line-
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 AlignInLineAction()
Constructs a newAlignInLineAction
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
Operation depends on the selected objects:private static Command
alignMultiWay(java.util.Collection<Way> ways)
Align way in case of multiple way #6819private static Command
alignOnlyNodes(java.util.List<Node> nodes)
Align nodes in case 3 or more nodes are selected.private static Command
alignSingleNode(Node node, java.util.List<AlignInLineAction.Line> lines)
Align a single node relative to a set of lines #9081Command
buildCommand(DataSet ds)
Builds "align in line" command depending on the selected objects.private static java.util.List<AlignInLineAction.Line>
getInvolvedLines(Node node, java.util.List<Way> refWays)
Get lines useful to do alignment of a single nodeprivate static Node[]
nodeFurthestAppart(java.util.List<Node> nodes)
Return the two nodes the most distant from the provided list.private static Node[]
nodePairFurthestApart(java.util.List<Node> nodes)
Return 2 nodes making up the line along which provided nodes must be aligned.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
-
AlignInLineAction
public AlignInLineAction()
Constructs a newAlignInLineAction
.
-
-
Method Detail
-
nodePairFurthestApart
private static Node[] nodePairFurthestApart(java.util.List<Node> nodes)
Return 2 nodes making up the line along which provided nodes must be aligned.- Parameters:
nodes
- Nodes to be aligned.- Returns:
- A array of two nodes.
- Throws:
java.lang.IllegalArgumentException
- if nodes is empty
-
nodeFurthestAppart
private static Node[] nodeFurthestAppart(java.util.List<Node> nodes)
Return the two nodes the most distant from the provided list.- Parameters:
nodes
- List of nodes to analyze.- Returns:
- An array containing the two most distant nodes.
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Operation depends on the selected objects:
-
buildCommand
public Command buildCommand(DataSet ds) throws AlignInLineAction.InvalidSelection
Builds "align in line" command depending on the selected objects.- Parameters:
ds
- data set in which the command operates- Returns:
- the resulting command to execute to perform action
- Throws:
AlignInLineAction.InvalidSelection
- if a polygon is selected, or if a node is used by 3 or more ways- Since:
- 13108
-
alignOnlyNodes
private static Command alignOnlyNodes(java.util.List<Node> nodes) throws AlignInLineAction.InvalidSelection
Align nodes in case 3 or more nodes are selected.- Parameters:
nodes
- Nodes to be aligned.- Returns:
- Command that perform action.
- Throws:
AlignInLineAction.InvalidSelection
- If the nodes have same coordinates.
-
alignMultiWay
private static Command alignMultiWay(java.util.Collection<Way> ways) throws AlignInLineAction.InvalidSelection
Align way in case of multiple way #6819- Parameters:
ways
- Collection of way to align- Returns:
- Command that perform action
- Throws:
AlignInLineAction.InvalidSelection
- if a polygon is selected, or if a node is used by 3 or more ways
-
getInvolvedLines
private static java.util.List<AlignInLineAction.Line> getInvolvedLines(Node node, java.util.List<Way> refWays) throws AlignInLineAction.InvalidSelection
Get lines useful to do alignment of a single node- Parameters:
node
- Node to be alignedrefWays
- Ways where useful lines will be searched- Returns:
- List of useful lines
- Throws:
AlignInLineAction.InvalidSelection
- if a node got more than 4 neighbours (self-crossing way)
-
alignSingleNode
private static Command alignSingleNode(Node node, java.util.List<AlignInLineAction.Line> lines) throws AlignInLineAction.InvalidSelection
Align a single node relative to a set of lines #9081- Parameters:
node
- Node to be alignedlines
- Lines to align node on- Returns:
- Command that perform action
- Throws:
AlignInLineAction.InvalidSelection
- if more than 2 lines
-
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()
-
-