org.openstreetmap.josm.actions
Class JoinAreasAction

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

public class JoinAreasAction
extends JosmAction

Join Areas (i.e. closed ways and multipolygons)

See Also:
Serialized Form

Nested Class Summary
static class JoinAreasAction.AssembledMultipolygon
           
static class JoinAreasAction.AssembledPolygon
          This helper class describes a polygon, assembled from several ways.
static class JoinAreasAction.JoinAreasResult
          This helper class describes join ares action result.
static class JoinAreasAction.Multipolygon
           
(package private) static class JoinAreasAction.PolygonLevel
          Helper storage class for finding findOuterWays
private static class JoinAreasAction.RelationRole
           
static class JoinAreasAction.WayInPolygon
           
private static class JoinAreasAction.WayTraverser
          This hepler class implements algorithm traversing trough connected ways.
 
Field Summary
private  java.util.LinkedList<Command> cmds
           
private  int cmdsCount
           
 
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
JoinAreasAction()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Gets called whenever the shortcut is pressed or the menu entry is selected Checks whether the selected objects are suitable to join and joins them if so
private  JoinAreasAction.RelationRole addOwnMultigonRelation(java.util.Collection<Way> inner, Way outer)
          Will add own multipolygon relation to the "previously existing" relations.
private  java.util.List<java.util.List<Node>> buildNodeChunks(Way way, java.util.Collection<Node> splitNodes)
          Simple chunking version.
private  java.util.List<JoinAreasAction.Multipolygon> collectMultipolygons(java.util.List<Way> selectedWays)
          This method analyzes multipolygon relationships of given ways and collects addition inner ways to consider.
private  void commitCommands(java.lang.String description)
          Commits the command list with a description
private  java.util.List<Relation> filterOwnMultipolygonRelations(java.util.Collection<Relation> relations, java.util.List<JoinAreasAction.Multipolygon> polygons)
          This method filters the list of relations that form the multipolygons.
static java.util.List<JoinAreasAction.AssembledPolygon> findBoundaryPolygons(java.util.Collection<JoinAreasAction.WayInPolygon> multigonWays, java.util.List<Way> discardedResult)
          Finds all ways that form inner or outer boundaries.
private  java.util.List<JoinAreasAction.PolygonLevel> findOuterWaysImpl(int level, java.util.Collection<JoinAreasAction.AssembledPolygon> boundaryWays)
          Collects outer way and corresponding inner ways from all boundaries.
private  java.util.List<JoinAreasAction.AssembledMultipolygon> findPolygons(java.util.Collection<JoinAreasAction.AssembledPolygon> boundaries)
          This method finds witch ways are outer and witch are inner.
private  void fixRelations(java.util.ArrayList<JoinAreasAction.RelationRole> rels, Way outer, JoinAreasAction.RelationRole ownMultipol, java.util.Set<Relation> relationsToDelete)
          Adds the previously removed relations again to the outer way.
static java.util.List<JoinAreasAction.AssembledPolygon> fixTouchingPolygons(java.util.List<JoinAreasAction.AssembledPolygon> polygons)
          This method checks if polygons have several touching parts and splits them in several polygons.
private  JoinAreasAction.JoinAreasResult joinAreas(java.util.List<JoinAreasAction.Multipolygon> areas)
          Will join two or more overlapping areas
private  Way joinOrientedWays(java.util.List<JoinAreasAction.WayInPolygon> ways)
          Joins a list of ways (using CombineWayAction and ReverseWayAction as specified in WayInPath)
private  JoinAreasAction.Multipolygon joinPolygon(JoinAreasAction.AssembledMultipolygon polygon)
          Joins the lists of ways.
private  Way joinWays(java.util.List<JoinAreasAction.WayInPolygon> ways)
          Joins the outer ways and deletes all short ways that can't be part of a multipolygon anyway.
private  void makeCommitsOneAction(java.lang.String message)
          Takes the last cmdsCount actions back and combines them into a single action (for when the user wants to undo the join action)
private  java.util.ArrayList<JoinAreasAction.WayInPolygon> markWayInsideSide(java.util.List<Way> parts, boolean isInner)
          This method analyzes the way and assigns each part what direction polygon "inside" is.
private  boolean removeDuplicateNodes(java.util.List<Way> ways)
          This method removes duplicate points (if any) from the input way.
private  java.util.ArrayList<JoinAreasAction.RelationRole> removeFromAllRelations(OsmPrimitive osm)
          Removes a given OsmPrimitive from all relations
private  boolean resolveTagConflicts(java.util.List<JoinAreasAction.Multipolygon> polygons)
          Checks if tags of two given ways differ, and presents the user a dialog to solve conflicts
private  java.util.ArrayList<Way> splitWayOnNodes(Way way, java.util.Set<Node> nodes)
          This is a method splits way into smaller parts, using the prepared nodes list as split points.
private  void stripTags(java.util.Collection<Way> ways)
           
private  void stripTags(Way x)
           
private  boolean testJoin(java.util.List<JoinAreasAction.Multipolygon> areas)
          Tests if the areas have some intersections to join.
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.
static boolean wayInsideWay(JoinAreasAction.AssembledPolygon inside, JoinAreasAction.AssembledPolygon outside)
          Tests if way is inside other way
 
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
 

Field Detail

cmds

private java.util.LinkedList<Command> cmds

cmdsCount

private int cmdsCount
Constructor Detail

JoinAreasAction

public JoinAreasAction()
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Gets called whenever the shortcut is pressed or the menu entry is selected Checks whether the selected objects are suitable to join and joins them if so


testJoin

private boolean testJoin(java.util.List<JoinAreasAction.Multipolygon> areas)
Tests if the areas have some intersections to join.

Parameters:
areas -
Returns:

joinAreas

private JoinAreasAction.JoinAreasResult joinAreas(java.util.List<JoinAreasAction.Multipolygon> areas)
                                           throws UserCancelException
Will join two or more overlapping areas

Parameters:
areas - - list of areas to join
Returns:
new area formed.
Throws:
UserCancelException

resolveTagConflicts

private boolean resolveTagConflicts(java.util.List<JoinAreasAction.Multipolygon> polygons)
Checks if tags of two given ways differ, and presents the user a dialog to solve conflicts

Parameters:
Way - First way to check
Way - Second Way to check
Returns:
boolean True if all conflicts are resolved, False if conflicts remain.

removeDuplicateNodes

private boolean removeDuplicateNodes(java.util.List<Way> ways)
This method removes duplicate points (if any) from the input way.

Parameters:
way - the way to process
Returns:
true if any changes where made

commitCommands

private void commitCommands(java.lang.String description)
Commits the command list with a description

Parameters:
String - The description of what the commands do

markWayInsideSide

private java.util.ArrayList<JoinAreasAction.WayInPolygon> markWayInsideSide(java.util.List<Way> parts,
                                                                            boolean isInner)
This method analyzes the way and assigns each part what direction polygon "inside" is.

Parameters:
parts - the split parts of the way
isInner - - if true, reverts the direction (for multipolygon islands)
Returns:
list of parts, marked with the inside orientation.

splitWayOnNodes

private java.util.ArrayList<Way> splitWayOnNodes(Way way,
                                                 java.util.Set<Node> nodes)
This is a method splits way into smaller parts, using the prepared nodes list as split points. Uses SplitWayAction.splitWay for the heavy lifting.

Returns:
list of split ways (or original ways if no splitting is done).

buildNodeChunks

private java.util.List<java.util.List<Node>> buildNodeChunks(Way way,
                                                             java.util.Collection<Node> splitNodes)
Simple chunking version. Does not care about circular ways and result being proper, we will glue it all back together later on.

Parameters:
way - the way to chunk
splitNodes - the places where to cut.
Returns:
list of node paths to produce.

findPolygons

private java.util.List<JoinAreasAction.AssembledMultipolygon> findPolygons(java.util.Collection<JoinAreasAction.AssembledPolygon> boundaries)
This method finds witch ways are outer and witch are inner.

Parameters:
boundaryWays -
Returns:

findOuterWaysImpl

private java.util.List<JoinAreasAction.PolygonLevel> findOuterWaysImpl(int level,
                                                                       java.util.Collection<JoinAreasAction.AssembledPolygon> boundaryWays)
Collects outer way and corresponding inner ways from all boundaries.

Parameters:
boundaryWays -
Returns:
the outermostWay.

findBoundaryPolygons

public static java.util.List<JoinAreasAction.AssembledPolygon> findBoundaryPolygons(java.util.Collection<JoinAreasAction.WayInPolygon> multigonWays,
                                                                                    java.util.List<Way> discardedResult)
Finds all ways that form inner or outer boundaries.

Parameters:
Collection - A list of (splitted) ways that form a multigon and share common end nodes on intersections.
Collection - this list is filled with ways that are to be discarded
Returns:
Collection> A list of ways that form the outer and inner boundaries of the multigon.

fixTouchingPolygons

public static java.util.List<JoinAreasAction.AssembledPolygon> fixTouchingPolygons(java.util.List<JoinAreasAction.AssembledPolygon> polygons)
This method checks if polygons have several touching parts and splits them in several polygons.

Parameters:
polygon - the polygon to process.

wayInsideWay

public static boolean wayInsideWay(JoinAreasAction.AssembledPolygon inside,
                                   JoinAreasAction.AssembledPolygon outside)
Tests if way is inside other way

Parameters:
outside -
inside -
Returns:

joinPolygon

private JoinAreasAction.Multipolygon joinPolygon(JoinAreasAction.AssembledMultipolygon polygon)
                                          throws UserCancelException
Joins the lists of ways.

Parameters:
Collection - The list of outer ways that belong to that multigon.
Returns:
Way The newly created outer way
Throws:
UserCancelException

joinWays

private Way joinWays(java.util.List<JoinAreasAction.WayInPolygon> ways)
              throws UserCancelException
Joins the outer ways and deletes all short ways that can't be part of a multipolygon anyway.

Parameters:
Collection - The list of outer ways that belong to that multigon.
Returns:
Way The newly created outer way
Throws:
UserCancelException

joinOrientedWays

private Way joinOrientedWays(java.util.List<JoinAreasAction.WayInPolygon> ways)
                      throws UserCancelException
Joins a list of ways (using CombineWayAction and ReverseWayAction as specified in WayInPath)

Parameters:
ArrayList - The list of ways to join and reverse
Returns:
Way The newly created way
Throws:
UserCancelException

collectMultipolygons

private java.util.List<JoinAreasAction.Multipolygon> collectMultipolygons(java.util.List<Way> selectedWays)
This method analyzes multipolygon relationships of given ways and collects addition inner ways to consider.

Parameters:
selectedWays - the selected ways
Returns:
list of polygons, or null if too complex relation encountered.

filterOwnMultipolygonRelations

private java.util.List<Relation> filterOwnMultipolygonRelations(java.util.Collection<Relation> relations,
                                                                java.util.List<JoinAreasAction.Multipolygon> polygons)
This method filters the list of relations that form the multipolygons.

Parameters:
relations -
polygons -
Returns:

addOwnMultigonRelation

private JoinAreasAction.RelationRole addOwnMultigonRelation(java.util.Collection<Way> inner,
                                                            Way outer)
Will add own multipolygon relation to the "previously existing" relations. Fixup is done by fixRelations

Parameters:
Collection - List of already closed inner ways
Way - The outer way
ArrayList - The list of relation with roles to add own relation to

removeFromAllRelations

private java.util.ArrayList<JoinAreasAction.RelationRole> removeFromAllRelations(OsmPrimitive osm)
Removes a given OsmPrimitive from all relations

Parameters:
OsmPrimitive - Element to remove from all relations
Returns:
ArrayList List of relations with roles the primitives was part of

fixRelations

private void fixRelations(java.util.ArrayList<JoinAreasAction.RelationRole> rels,
                          Way outer,
                          JoinAreasAction.RelationRole ownMultipol,
                          java.util.Set<Relation> relationsToDelete)
Adds the previously removed relations again to the outer way. If there are multiple multipolygon relations where the joined areas were in "outer" role a new relation is created instead with all members of both. This function depends on multigon relations to be valid already, it won't fix them.

Parameters:
ArrayList - List of relations with roles the (original) ways were part of
Way - The newly created outer area/way
relationsToDelete - - set of relations to delete.

stripTags

private void stripTags(java.util.Collection<Way> ways)
Parameters:
Collection - The List of Ways to remove all tags from

stripTags

private void stripTags(Way x)
Parameters:
Way - The Way to remove all tags from

makeCommitsOneAction

private void makeCommitsOneAction(java.lang.String message)
Takes the last cmdsCount actions back and combines them into a single action (for when the user wants to undo the join action)

Parameters:
String - The commit message to display

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