Changeset 8294 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java
r7937 r8294 11 11 import java.util.Collection; 12 12 import java.util.Iterator; 13 import java.util.LinkedList; 13 14 import java.util.List; 14 15 … … 20 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 22 import org.openstreetmap.josm.data.osm.Way; 23 import org.openstreetmap.josm.gui.Notification; 22 24 import org.openstreetmap.josm.tools.Shortcut; 23 25 … … 39 41 } 40 42 43 /** 44 * Called when the action is executed. 45 */ 41 46 @Override 42 47 public void actionPerformed(ActionEvent e) { … … 46 51 List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class); 47 52 List<Way> selectedWays = OsmPrimitive.getFilteredList(selection, Way.class); 53 54 selectedNodes = cleanSelectedNodes(selectedWays, selectedNodes); 55 48 56 List<Way> applicableWays = getApplicableWays(selectedWays, selectedNodes); 49 57 50 58 if (applicableWays == null) { 51 JOptionPane.showMessageDialog( 52 Main.parent, 53 tr("Select at least one node to be disconnected."), 54 tr("Warning"), 55 JOptionPane.WARNING_MESSAGE); 59 notify(tr("Select at least one node to be disconnected."), 60 JOptionPane.WARNING_MESSAGE); 56 61 return; 57 62 } else if (applicableWays.isEmpty()) { 58 JOptionPane.showMessageDialog(Main.parent, 59 trn("Selected node cannot be disconnected from anything.", 60 "Selected nodes cannot be disconnected from anything.", 61 selectedNodes.size()), 62 tr("Warning"), 63 JOptionPane.WARNING_MESSAGE); 63 notify(trn("Selected node cannot be disconnected from anything.", 64 "Selected nodes cannot be disconnected from anything.", 65 selectedNodes.size()), 66 JOptionPane.WARNING_MESSAGE); 64 67 return; 65 68 } else if (applicableWays.size() > 1) { 66 JOptionPane.showMessageDialog(Main.parent,67 trn("There is more than one way using the node you selected.Please select the way also.",68 Please select the way also.",69 select edNodes.size()),70 tr("Warning"),71 69 notify(trn("There is more than one way using the node you selected. " 70 + "Please select the way also.", 71 "There is more than one way using the nodes you selected. " 72 + "Please select the way also.", 73 selectedNodes.size()), 74 JOptionPane.WARNING_MESSAGE); 72 75 return; 73 76 } else if (applicableWays.get(0).getRealNodesCount() < selectedNodes.size() + 2) { 74 77 // there is only one affected way, but removing the selected nodes would only leave it 75 78 // with less than 2 nodes 76 JOptionPane.showMessageDialog(Main.parent,77 trn("The affected way would disappear after disconnecting theselected node.",78 selected nodes.",79 Nodes.size()),80 tr("Warning"),81 79 notify(trn("The affected way would disappear after disconnecting the " 80 + "selected node.", 81 "The affected way would disappear after disconnecting the " 82 + "selected nodes.", 83 selectedNodes.size()), 84 JOptionPane.WARNING_MESSAGE); 82 85 return; 83 86 } 84 85 87 86 88 // Finally, applicableWays contains only one perfect way … … 92 94 } 93 95 94 // Find ways to which the disconnect can be applied. This is the list of ways with more 95 // than two nodes which pass through all the given nodes, intersected with the selected ways (if any) 96 /** 97 * Send a notification message. 98 * @param msg Message to be sent. 99 * @param messageType Nature of the message. 100 */ 101 public void notify(String msg, int messageType) { 102 new Notification(msg).setIcon(messageType).show(); 103 } 104 105 /** 106 * Removes irrelevant nodes from user selection. 107 * 108 * The action can be performed reliably even if we remove : 109 * * Nodes not referenced by any ways 110 * * When only one way is selected, nodes not part of this way (#10396). 111 * 112 * @param selectedWays List of user selected way. 113 * @param selectedNodes List of user selected nodes. 114 * @return New list of nodes cleaned of irrelevant nodes. 115 */ 116 private List<Node> cleanSelectedNodes(List<Way> selectedWays, 117 List<Node> selectedNodes) { 118 List<Node> resultingNodes = new LinkedList<>(); 119 120 // List of node referenced by a route 121 for (Node n: selectedNodes) { 122 if (n.isReferredByWays(1)) { 123 resultingNodes.add(n); 124 } 125 } 126 // If exactly one selected way, remove node not referencing par this way. 127 if (selectedWays.size() == 1) { 128 Way w = selectedWays.get(0); 129 for (Node n: new ArrayList<Node>(resultingNodes)) { 130 if (!w.containsNode(n)) { 131 resultingNodes.remove(n); 132 } 133 } 134 } 135 // Warn if nodes were removed 136 if (resultingNodes.size() != selectedNodes.size()) { 137 notify(tr("Some irrelevant nodes have been removed from the selection"), 138 JOptionPane.INFORMATION_MESSAGE); 139 } 140 return resultingNodes; 141 } 142 143 /** 144 * Find ways to which the disconnect can be applied. This is the list of ways 145 * with more than two nodes which pass through all the given nodes, intersected 146 * with the selected ways (if any) 147 * @param selectedWays List of user selected ways. 148 * @param selectedNodes List of user selected nodes. 149 * @return List of relevant ways 150 */ 96 151 private List<Way> getApplicableWays(List<Way> selectedWays, List<Node> selectedNodes) { 97 152 if (selectedNodes.isEmpty())
Note:
See TracChangeset
for help on using the changeset viewer.