Changeset 35674 in osm for applications/editors/josm/plugins
- Timestamp:
- 2020-12-22T14:11:32+01:00 (4 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AlignWayNodesAction.java
r35579 r35674 11 11 import java.util.List; 12 12 import java.util.Set; 13 import java.util.stream.Collectors;14 13 15 14 import javax.swing.JOptionPane; … … 27 26 28 27 /** 29 * Pastes relation membership from objects in the paste buffer onto selected object(s).28 * Align way nodes. Similar to Align nodes in line, but uses a parent way as context. 30 29 * 31 30 * @author Zverik … … 139 138 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 140 139 Set<Node> nodes = filterNodes(selection); 141 Set<Way> ways = findCommonWays(nodes); 142 setEnabled(ways != null && ways.size() == 1 && !nodes.isEmpty()); 143 } 144 145 private Set<Way> findCommonWays(Set<Node> nodes) { 140 if (nodes.isEmpty()) 141 setEnabled(false); 142 else { 143 Set<Way> ways = findCommonWays(nodes); 144 setEnabled(ways != null && ways.size() == 1); 145 } 146 } 147 148 private static Set<Way> findCommonWays(Set<Node> nodes) { 146 149 Set<Way> ways = null; 147 for (Node n : nodes.stream().filter(n -> n.getDataSet() != null).collect(Collectors.toList())) { 150 for (Node n : nodes) { 151 if (n.getDataSet() == null) 152 continue; 148 153 if (ways == null) 149 154 ways = new HashSet<>(n.getParentWays()); 150 155 else { 151 156 ways.retainAll(n.getParentWays()); 157 if (ways.isEmpty()) 158 break; 152 159 } 153 160 } … … 155 162 } 156 163 157 private Set<Node> filterNodes(Collection<? extends OsmPrimitive> selection) {164 private static Set<Node> filterNodes(Collection<? extends OsmPrimitive> selection) { 158 165 Set<Node> result = new HashSet<>(); 159 166 if (selection != null) { … … 174 181 * @return the index of the node right after the largest empty span 175 182 */ 176 private int findFirstNode(Way way, Set<Node> nodes) {183 private static int findFirstNode(Way way, Set<Node> nodes) { 177 184 int pos = 0; 178 185 while (pos < way.getNodesCount() && !nodes.contains(way.getNode(pos))) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
r35617 r35674 169 169 nodeToReplace = findNearestNode(subjectNode, nodePool.stream().filter(Node::isNew).collect(Collectors.toList())); 170 170 if (nodeToReplace == null) { 171 171 nodeToReplace = findNearestNode(subjectNode, nodePool); 172 172 } 173 173 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentWaysAction.java
r35579 r35674 60 60 @Override 61 61 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 62 if (selection == null) { 63 setEnabled(false); 64 return; 65 } 66 setEnabled(!selection.isEmpty()); 62 setEnabled(selection != null && !selection.isEmpty()); 67 63 } 68 64 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/ConnectedWaysAction.java
r35579 r35674 57 57 @Override 58 58 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 59 if (selection == null) { 60 setEnabled(false); 61 return; 62 } 63 setEnabled(!selection.isEmpty()); 59 setEnabled(selection != null && !selection.isEmpty()); 64 60 } 65 61 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysAction.java
r35579 r35674 58 58 @Override 59 59 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 60 if (selection == null) { 61 setEnabled(false); 62 return; 63 } 64 setEnabled(!selection.isEmpty()); 60 setEnabled(selection != null && !selection.isEmpty()); 65 61 } 66 62 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysRecursiveAction.java
r35579 r35674 58 58 @Override 59 59 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 60 if (selection == null) { 61 setEnabled(false); 62 return; 63 } 64 setEnabled(!selection.isEmpty()); 60 setEnabled(selection != null && !selection.isEmpty()); 65 61 } 66 62 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/MiddleNodesAction.java
r35579 r35674 60 60 @Override 61 61 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 62 if (selection == null) { 63 setEnabled(false); 64 return; 65 } 66 setEnabled(!selection.isEmpty()); 62 setEnabled(selection != null && !selection.isEmpty()); 67 63 } 68 64 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectAllInsideAction.java
r35613 r35674 56 56 @Override 57 57 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 58 if (selection == null) { 59 setEnabled(false); 60 return; 61 } 62 setEnabled(!selection.isEmpty()); 58 setEnabled(selection != null && !selection.isEmpty()); 63 59 } 64 60 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectHighwayAction.java
r35579 r35674 119 119 @Override 120 120 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 121 if (selection == null) { 122 setEnabled(false); 123 return; 124 } 125 int count = 0, rank = 100; 126 for (OsmPrimitive p : selection) { 127 if (p instanceof Way) { 128 count++; 129 rank = Math.min(rank, getHighwayRank(p)); 121 int count = 0; 122 int rank = 100; 123 if (selection != null) { 124 for (OsmPrimitive p : selection) { 125 if (p instanceof Way) { 126 count++; 127 if (count > 2) 128 break; 129 rank = Math.min(rank, getHighwayRank(p)); 130 } 130 131 } 131 132 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UnselectNodesAction.java
r35579 r35674 41 41 @Override 42 42 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 43 if (selection == null) { 44 setEnabled(false); 45 return; 46 } 47 setEnabled(!selection.isEmpty()); 43 setEnabled(selection != null && !selection.isEmpty()); 48 44 } 49 45 }
Note:
See TracChangeset
for help on using the changeset viewer.