Class 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
    • Constructor Detail

      • DistributeAction

        public DistributeAction()
        Constructs a new DistributeAction.
    • 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 ways
        nodes - Selected nodes
        Returns:
        true in this case
      • distributeWay

        private static java.util.Collection<CommanddistributeWay​(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 ways
        nodes - Selected nodes
        Returns:
        true in this case
      • distributeNodes

        private static java.util.Collection<CommanddistributeNodes​(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<NoderemoveNodesWithoutCoordinates​(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