Changeset 32410 in osm for applications/editors/josm/plugins/utilsplugin2/src
- Timestamp:
- 2016-06-26T17:19:30+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2
- Files:
-
- 53 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/UtilsPlugin2.java
r32097 r32410 1 // License: GPL v2 or later. See LICENSE filefor details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2; 3 3 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AddIntersectionsAction.java
r32333 r32410 28 28 29 29 public class AddIntersectionsAction extends JosmAction { 30 30 31 31 /** 32 32 * Constructs a new {@code AddIntersectionsAction}. … … 34 34 public AddIntersectionsAction() { 35 35 super(tr("Add nodes at intersections"), "addintersect", tr("Add missing nodes at intersections of selected ways."), 36 Shortcut.registerShortcut("tools:addintersect", tr("Tool: {0}", tr("Add nodes at intersections")), KeyEvent.VK_I, Shortcut.SHIFT), true); 36 Shortcut.registerShortcut("tools:addintersect", tr("Tool: {0}", tr("Add nodes at intersections")), 37 KeyEvent.VK_I, Shortcut.SHIFT), 38 true); 37 39 putValue("help", ht("/Action/AddIntersections")); 38 40 } … … 45 47 if (ways.isEmpty()) { 46 48 new Notification( 47 tr("Please select one or more ways with intersections of segments.")) 48 49 49 tr("Please select one or more ways with intersections of segments.")) 50 .setIcon(JOptionPane.INFORMATION_MESSAGE) 51 .show(); 50 52 return; 51 53 } … … 54 56 Geometry.addIntersections(ways, false, cmds); 55 57 if (!cmds.isEmpty()) { 56 Main.main.undoRedo.add(new SequenceCommand(tr("Add nodes at intersections"),cmds)); 58 Main.main.undoRedo.add(new SequenceCommand(tr("Add nodes at intersections"), cmds)); 57 59 Set<Node> nodes = new HashSet<>(10); 58 60 // find and select newly added nodes 59 for (Command cmd: cmds) if (cmd instanceof AddCommand){ 61 for (Command cmd: cmds) if (cmd instanceof AddCommand) { 60 62 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 61 for ( 63 for (OsmPrimitive p : pp) { // find all affected nodes 62 64 if (p instanceof Node && p.isNew()) 63 nodes.add((Node)p); 65 nodes.add((Node) p); 64 66 } 65 67 if (!nodes.isEmpty()) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AlignWayNodesAction.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.actions; 2 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.event.ActionEvent; 3 7 import java.awt.event.KeyEvent; 8 import java.util.ArrayList; 9 import java.util.Collection; 10 import java.util.HashSet; 11 import java.util.List; 12 import java.util.Set; 13 14 import javax.swing.JOptionPane; 15 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.actions.JosmAction; 18 import org.openstreetmap.josm.command.Command; 19 import org.openstreetmap.josm.command.MoveCommand; 20 import org.openstreetmap.josm.command.SequenceCommand; 21 import org.openstreetmap.josm.data.osm.Node; 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.Way; 24 import org.openstreetmap.josm.gui.Notification; 4 25 import org.openstreetmap.josm.tools.Shortcut; 5 import org.openstreetmap.josm.data.osm.*;6 import org.openstreetmap.josm.Main;7 import org.openstreetmap.josm.command.*;8 import java.util.*;9 import java.awt.event.ActionEvent;10 import javax.swing.JOptionPane;11 import org.openstreetmap.josm.actions.JosmAction;12 import org.openstreetmap.josm.gui.Notification;13 import static org.openstreetmap.josm.tools.I18n.tr;14 26 15 27 /** … … 27 39 public AlignWayNodesAction() { 28 40 super(TITLE, "dumbutils/alignwaynodes", tr("Align nodes in a way"), 29 Shortcut.registerShortcut("tools:alignwaynodes", tr("Tool: {0}", tr("Align Way Nodes")), KeyEvent.VK_L, Shortcut.SHIFT) 30 , true); 31 } 32 33 public void actionPerformed( ActionEvent e ) { 41 Shortcut.registerShortcut("tools:alignwaynodes", tr("Tool: {0}", tr("Align Way Nodes")), KeyEvent.VK_L, Shortcut.SHIFT), 42 true); 43 } 44 45 @Override 46 public void actionPerformed(ActionEvent e) { 34 47 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 35 48 Set<Node> selectedNodes = filterNodes(selection); 36 49 int selectedNodesCount = selectedNodes.size(); 37 50 Set<Way> ways = findCommonWays(selectedNodes); 38 if (ways == null || ways.size() != 1 || selectedNodesCount == 051 if (ways == null || ways.size() != 1 || selectedNodesCount == 0) 39 52 return; 40 53 Way way = ways.iterator().next(); 41 if (way.getNodesCount() < (way.isClosed() ? 4 : 3)54 if (way.getNodesCount() < (way.isClosed() ? 4 : 3)) { 42 55 new Notification(tr("The way with selected nodes can not be straightened.")) 43 56 .setIcon(JOptionPane.ERROR_MESSAGE).show(); 44 57 return; 45 58 } … … 51 64 int i = firstNodePos; 52 65 boolean iterated = false; 53 while (!iterated || i != lastNodePos66 while (!iterated || i != lastNodePos) { 54 67 Node node = way.getNode(i); 55 if (selectedNodes.contains(node)68 if (selectedNodes.contains(node)) { 56 69 nodes.add(node); 57 70 selectedNodes.remove(node); 58 if (selectedNodesCount == 159 nodes.add(0, way.getNode( 60 nodes.add(way.getNode( 71 if (selectedNodesCount == 1) { 72 nodes.add(0, way.getNode(i > 0 ? i - 1 : way.isClosed() ? way.getNodesCount() - 2 : i + 2)); 73 nodes.add(way.getNode(i + 1 < way.getNodesCount() ? i + 1 : way.isClosed() ? 1 : i - 2)); 61 74 } 62 if (selectedNodes.isEmpty()75 if (selectedNodes.isEmpty()) 63 76 break; 64 } else if (selectedNodesCount == 2 && selectedNodes.size() == 177 } else if (selectedNodesCount == 2 && selectedNodes.size() == 1) 65 78 nodes.add(node); 66 79 i++; 67 if (i >= way.getNodesCount() && way.isClosed()80 if (i >= way.getNodesCount() && way.isClosed()) 68 81 i = 0; 69 82 iterated = true; 70 83 } 71 84 72 if (nodes.size() < 385 if (nodes.size() < 3) { 73 86 new Notification(tr("Internal error: number of nodes is {0}.", nodes.size())) 74 87 .setIcon(JOptionPane.ERROR_MESSAGE).show(); 75 88 return; 76 89 } … … 83 96 double bx = nodes.get(nodes.size() - 1).getEastNorth().east(); 84 97 double by = nodes.get(nodes.size() - 1).getEastNorth().north(); 85 86 for (i = 1; i + 1 < nodes.size(); i++98 99 for (i = 1; i + 1 < nodes.size(); i++) { 87 100 Node n = nodes.get(i); 88 101 89 102 // Algorithm is copied from org.openstreetmap.josm.actions.AlignInLineAction 90 103 double nx = n.getEastNorth().east(); 91 104 double ny = n.getEastNorth().north(); 92 105 93 if (ax == bx106 if (ax == bx) { 94 107 // Special case if AB is vertical... 95 108 nx = ax; 96 } else if (ay == by109 } else if (ay == by) { 97 110 // ...or horizontal 98 111 ny = ay; … … 109 122 110 123 // Add the command to move the node to its new position. 111 if (Math.abs(nx - n.getEastNorth().east()) > MOVE_THRESHOLD && Math.abs(ny - n.getEastNorth().north()) > MOVE_THRESHOLD124 if (Math.abs(nx - n.getEastNorth().east()) > MOVE_THRESHOLD && Math.abs(ny - n.getEastNorth().north()) > MOVE_THRESHOLD) 112 125 commands.add(new MoveCommand(n, nx - n.getEastNorth().east(), ny - n.getEastNorth().north())); 113 126 } 114 127 115 if (!commands.isEmpty()128 if (!commands.isEmpty()) 116 129 Main.main.undoRedo.add(new SequenceCommand(TITLE, commands)); 117 130 } … … 123 136 124 137 @Override 125 protected void updateEnabledState( 138 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 126 139 Set<Node> nodes = filterNodes(selection); 127 140 Set<Way> ways = findCommonWays(nodes); … … 129 142 } 130 143 131 private Set<Way> findCommonWays( 144 private Set<Way> findCommonWays(Set<Node> nodes) { 132 145 Set<Way> ways = null; 133 for (Node n : nodes146 for (Node n : nodes) { 134 147 List<Way> referrers = OsmPrimitive.getFilteredList(n.getReferrers(), Way.class); 135 if (ways == null148 if (ways == null) 136 149 ways = new HashSet<>(referrers); 137 150 else { … … 142 155 } 143 156 144 private Set<Node> filterNodes( 157 private Set<Node> filterNodes(Collection<? extends OsmPrimitive> selection) { 145 158 Set<Node> result = new HashSet<>(); 146 if( selection != null ) { 147 for( OsmPrimitive p : selection ) 148 if( p instanceof Node ) 149 result.add((Node)p); 159 if (selection != null) { 160 for (OsmPrimitive p : selection) { 161 if (p instanceof Node) 162 result.add((Node) p); 163 } 150 164 } 151 165 return result; … … 157 171 * TODO: not the maximum node count, but maximum distance! 158 172 */ 159 private int findFirstNode( 173 private int findFirstNode(Way way, Set<Node> nodes) { 160 174 int pos = 0; 161 while (pos < way.getNodesCount() && !nodes.contains(way.getNode(pos)))175 while (pos < way.getNodesCount() && !nodes.contains(way.getNode(pos))) { 162 176 pos++; 163 if( pos >= way.getNodesCount() ) 177 } 178 if (pos >= way.getNodesCount()) 164 179 return 0; 165 if (!way.isClosed() || nodes.size() <= 1180 if (!way.isClosed() || nodes.size() <= 1) 166 181 return pos; 167 182 … … 170 185 int maxLength = 0; 171 186 int lastPos = 0; 172 while (!fullCircle187 while (!fullCircle) { 173 188 int length = 0; 174 189 boolean skippedFirst = false; 175 while (!(skippedFirst && nodes.contains(way.getNode(pos)))190 while (!(skippedFirst && nodes.contains(way.getNode(pos)))) { 176 191 skippedFirst = true; 177 192 length++; 178 193 pos++; 179 if (pos >= way.getNodesCount()194 if (pos >= way.getNodesCount()) { 180 195 pos = 0; 181 196 fullCircle = true; 182 197 } 183 198 } 184 if (length > maxLength199 if (length > maxLength) { 185 200 maxLength = length; 186 201 lastPos = pos; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/ExtractPointAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.actions; 3 3 4 import java.awt.Point;5 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 6 5 import static org.openstreetmap.josm.tools.I18n.tr; 7 6 7 import java.awt.Point; 8 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.KeyEvent; … … 11 11 import java.util.LinkedList; 12 12 import java.util.List; 13 13 14 import javax.swing.JOptionPane; 15 14 16 import org.openstreetmap.josm.Main; 15 17 import org.openstreetmap.josm.actions.JosmAction; … … 19 21 import org.openstreetmap.josm.command.MoveCommand; 20 22 import org.openstreetmap.josm.command.SequenceCommand; 21 import org.openstreetmap.josm.data.osm.*; 23 import org.openstreetmap.josm.data.osm.Node; 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 25 import org.openstreetmap.josm.data.osm.Way; 22 26 import org.openstreetmap.josm.gui.Notification; 23 24 27 import org.openstreetmap.josm.tools.Shortcut; 25 28 … … 35 38 super(tr("Extract node"), "extnode", 36 39 tr("Extracts node from a way"), 37 Shortcut.registerShortcut("tools:extnode", tr("Tool: {0}","Extract node"), 38 KeyEvent.VK_J, Shortcut.ALT_SHIFT), true); 40 Shortcut.registerShortcut("tools:extnode", tr("Tool: {0}", "Extract node"), 41 KeyEvent.VK_J, Shortcut.ALT_SHIFT), true); 39 42 putValue("help", ht("/Action/ExtractNode")); 40 43 } … … 44 47 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 45 48 List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class); 46 if (selectedNodes.size() !=1) {49 if (selectedNodes.size() != 1) { 47 50 new Notification(tr("This tool extracts node from its ways and requires single node to be selected.")) 48 51 .setIcon(JOptionPane.WARNING_MESSAGE).show(); 49 52 return; 50 53 } … … 55 58 Point p = Main.map.mapView.getMousePosition(); 56 59 if (p != null) 57 cmds.add(new MoveCommand(nd,Main.map.mapView.getLatLon(p.x, p.y))); 60 cmds.add(new MoveCommand(nd, Main.map.mapView.getLatLon(p.x, p.y))); 58 61 List<OsmPrimitive> refs = nd.getReferrers(); 59 62 cmds.add(new AddCommand(ndCopy)); 60 63 61 64 for (OsmPrimitive pr: refs) { 62 65 if (pr instanceof Way) { 63 Way w =(Way)pr;66 Way w = (Way) pr; 64 67 List<Node> nodes = w.getNodes(); 65 int idx =nodes.indexOf(nd);68 int idx = nodes.indexOf(nd); 66 69 nodes.set(idx, ndCopy); // replace node with its copy 67 70 cmds.add(new ChangeNodesCommand(w, nodes)); 68 71 } 69 72 } 70 if (cmds.size() >1) Main.main.undoRedo.add(new SequenceCommand(tr("Extract node from line"),cmds));73 if (cmds.size() > 1) Main.main.undoRedo.add(new SequenceCommand(tr("Extract node from line"), cmds)); 71 74 } 72 75 … … 82 85 return; 83 86 } 84 setEnabled(selection.size() ==1);87 setEnabled(selection.size() == 1); 85 88 } 86 89 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteRelationsAction.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.actions; 2 3 … … 32 33 public PasteRelationsAction() { 33 34 super(TITLE, "dumbutils/pasterelations", tr("Paste relation membership from objects in the buffer onto selected object(s)"), 34 Shortcut.registerShortcut("tools:pasterelations", tr("Tool: {0}", tr("Paste Relations")), KeyEvent.VK_V, Shortcut.ALT_CTRL), true); 35 Shortcut.registerShortcut("tools:pasterelations", tr("Tool: {0}", tr("Paste Relations")), KeyEvent.VK_V, Shortcut.ALT_CTRL), 36 true); 35 37 } 36 38 37 39 @Override 38 public void actionPerformed( 40 public void actionPerformed(ActionEvent e) { 39 41 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 40 if (selection.isEmpty()42 if (selection.isEmpty()) 41 43 return; 42 44 43 45 Map<Relation, String> relations = new HashMap<>(); 44 for (PrimitiveData pdata : Main.pasteBuffer.getDirectlyAdded()46 for (PrimitiveData pdata : Main.pasteBuffer.getDirectlyAdded()) { 45 47 OsmPrimitive p = getLayerManager().getEditDataSet().getPrimitiveById(pdata.getUniqueId(), pdata.getType()); 46 48 if (p != null) { 47 (Relation r : OsmPrimitive.getFilteredList(p.getReferrers(), Relation.class)) {48 49 (RelationMember m : r.getMembers()50 (m.getMember().equals(p)51 52 (newRole != null && role == null53 54 (newRole != null ? !newRole.equals(role) : role != null55 56 57 58 59 60 61 49 for (Relation r : OsmPrimitive.getFilteredList(p.getReferrers(), Relation.class)) { 50 String role = relations.get(r); 51 for (RelationMember m : r.getMembers()) { 52 if (m.getMember().equals(p)) { 53 String newRole = m.getRole(); 54 if (newRole != null && role == null) 55 role = newRole; 56 else if (newRole != null ? !newRole.equals(role) : role != null) { 57 role = ""; 58 break; 59 } 60 } 61 } 62 relations.put(r, role); 63 } 62 64 } 63 65 } 64 66 65 67 List<Command> commands = new ArrayList<>(); 66 for (Relation rel : relations.keySet()68 for (Relation rel : relations.keySet()) { 67 69 Relation r = new Relation(rel); 68 70 boolean changed = false; 69 for (OsmPrimitive p : selection70 if (!r.getMemberPrimitives().contains(p) && !r.equals(p)71 for (OsmPrimitive p : selection) { 72 if (!r.getMemberPrimitives().contains(p) && !r.equals(p)) { 71 73 String role = relations.get(rel); 72 74 if ("associatedStreet".equals(r.get("type"))) { 73 75 if (p.get("highway") != null) { 74 role ="street";76 role = "street"; 75 77 } else if (p.get("addr:housenumber") != null) { 76 role ="house";78 role = "house"; 77 79 } 78 80 } … … 81 83 } 82 84 } 83 if (changed85 if (changed) 84 86 commands.add(new ChangeCommand(rel, r)); 85 87 } 86 88 87 if (!commands.isEmpty()89 if (!commands.isEmpty()) 88 90 Main.main.undoRedo.add(new SequenceCommand(TITLE, commands)); 89 91 } … … 95 97 96 98 @Override 97 protected void updateEnabledState( 98 setEnabled(selection != null && !selection.isEmpty() && !Main.pasteBuffer.isEmpty() 99 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 100 setEnabled(selection != null && !selection.isEmpty() && !Main.pasteBuffer.isEmpty()); 99 101 } 100 102 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitObjectAction.java
r32333 r32410 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.actions; 3 3 … … 26 26 import org.openstreetmap.josm.data.osm.Way; 27 27 import org.openstreetmap.josm.gui.Notification; 28 29 28 import org.openstreetmap.josm.tools.Shortcut; 30 29 … … 44 43 public SplitObjectAction() { 45 44 super(tr("Split Object"), "splitobject", tr("Split an object at the selected nodes."), 46 Shortcut.registerShortcut("tools:splitobject", tr("Tool: {0}", tr("Split Object")), 47 KeyEvent.VK_X, Shortcut.ALT) 48 , true); 45 Shortcut.registerShortcut("tools:splitobject", tr("Tool: {0}", tr("Split Object")), KeyEvent.VK_X, Shortcut.ALT), 46 true); 49 47 putValue("help", ht("/Action/SplitObject")); 50 48 } … … 75 73 for (Way selWay : selectedWays) { // we assume not more 2 ways in the list 76 74 if (selWay != null && // If one of selected ways is not closed we have it to get split points 77 selWay.isUsable() && 78 !selWay.isClosed() && 79 selWay.getKeys().isEmpty()) { 80 81 82 75 selWay.isUsable() && 76 !selWay.isClosed() && 77 selWay.getKeys().isEmpty()) { 78 selectedNodes.add(selWay.firstNode()); 79 selectedNodes.add(selWay.lastNode()); 80 splitWay = selWay; 83 81 } else { 84 82 selectedWay = selWay; // use another way as selected way … … 114 112 if (wayOccurenceCounter.isEmpty()) { 115 113 showWarningNotification( 116 trn("The selected node is not in the middle of any way.", 117 "The selected nodes are not in the middle of any way.", 118 selectedNodes.size())); 114 trn("The selected node is not in the middle of any way.", 115 "The selected nodes are not in the middle of any way.", 116 selectedNodes.size())); 119 117 return; 120 118 } … … 124 122 if (selectedWay != null) { 125 123 showWarningNotification( 126 trn("There is more than one way using the node you selected. Please select the way also.", 127 "There is more than one way using the nodes you selected. Please select the way also.", 128 selectedNodes.size()) 129 ); 124 trn("There is more than one way using the node you selected. Please select the way also.", 125 "There is more than one way using the nodes you selected. Please select the way also.", 126 selectedNodes.size()) 127 ); 130 128 return; 131 129 } … … 150 148 if (!nds.isEmpty()) { 151 149 showWarningNotification( 152 trn("The selected way does not contain the selected node.", 153 "The selected way does not contain all the selected nodes.", 154 selectedNodes.size())); 150 trn("The selected way does not contain the selected node.", 151 "The selected way does not contain all the selected nodes.", 152 selectedNodes.size())); 155 153 return; 156 154 } 157 155 } else if (selectedWay != null && selectedNodes.isEmpty()) { 158 156 showWarningNotification( 159 tr("The selected way is not a split way, please select split points or split way too.")); 157 tr("The selected way is not a split way, please select split points or split way too.")); 160 158 return; 161 159 } … … 183 181 (nodeIndex2 == 0 && nodeIndex1 == selectedWay.getNodesCount() - 2)) { 184 182 showWarningNotification( 185 tr("The selected nodes can not be consecutive nodes in the object.")); 183 tr("The selected nodes can not be consecutive nodes in the object.")); 186 184 return; 187 185 } … … 253 251 setEnabled(checkSelection(selection)); 254 252 } 255 253 256 254 void showWarningNotification(String msg) { 257 255 new Notification(msg) 258 256 .setIcon(JOptionPane.WARNING_MESSAGE).show(); 259 257 } 260 258 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitOnIntersectionsAction.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.actions; 2 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.event.ActionEvent; 7 import java.awt.event.KeyEvent; 8 import java.util.ArrayList; 9 import java.util.Collection; 10 import java.util.HashMap; 11 import java.util.Iterator; 12 import java.util.List; 13 import java.util.Map; 14 3 15 import javax.swing.JOptionPane; 16 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.actions.JosmAction; 4 19 import org.openstreetmap.josm.actions.SplitWayAction; 20 import org.openstreetmap.josm.command.Command; 21 import org.openstreetmap.josm.command.SequenceCommand; 5 22 import org.openstreetmap.josm.data.osm.Node; 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 6 24 import org.openstreetmap.josm.data.osm.Way; 7 import org.openstreetmap.josm.Main; 8 import org.openstreetmap.josm.command.*; 9 import java.util.*; 10 import java.awt.event.KeyEvent; 25 import org.openstreetmap.josm.gui.Notification; 11 26 import org.openstreetmap.josm.tools.Shortcut; 12 import java.awt.event.ActionEvent;13 import org.openstreetmap.josm.actions.JosmAction;14 import org.openstreetmap.josm.data.osm.OsmPrimitive;15 import org.openstreetmap.josm.gui.Notification;16 import static org.openstreetmap.josm.tools.I18n.tr;17 27 18 28 /** … … 28 38 super(TITLE, "dumbutils/splitonintersections", tr("Split adjacent ways on T-intersections"), 29 39 Shortcut.registerShortcut("tools:splitonintersections", tr("Tool: {0}", tr("Split adjacent ways")), 30 KeyEvent.VK_P, Shortcut.ALT_CTRL_SHIFT), true); 40 KeyEvent.VK_P, Shortcut.ALT_CTRL_SHIFT), true); 31 41 } 32 42 33 43 @Override 34 public void actionPerformed( 44 public void actionPerformed(ActionEvent e) { 35 45 List<Command> list = new ArrayList<>(); 36 46 List<Way> selectedWays = OsmPrimitive.getFilteredList(getLayerManager().getEditDataSet().getSelected(), Way.class); 37 47 Map<Way, List<Node>> splitWays = new HashMap<>(); 38 48 39 for( Way way : selectedWays ) { 40 if( way.getNodesCount() > 1 && !way.hasIncompleteNodes() && !way.isClosed() ) 41 for( Node node : new Node[] {way.getNode(0), way.getNode(way.getNodesCount() - 1)} ) { 42 List<Way> refs = OsmPrimitive.getFilteredList(node.getReferrers(), Way.class); 43 refs.remove(way); 44 if( selectedWays.size() > 1 ) { 45 // When several ways are selected, split only those among selected 49 for (Way way : selectedWays) { 50 if (way.getNodesCount() > 1 && !way.hasIncompleteNodes() && !way.isClosed()) 51 for (Node node : new Node[] {way.getNode(0), way.getNode(way.getNodesCount() - 1)}) { 52 List<Way> refs = OsmPrimitive.getFilteredList(node.getReferrers(), Way.class); 53 refs.remove(way); 54 if (selectedWays.size() > 1) { 55 // When several ways are selected, split only those among selected 56 Iterator<Way> it = refs.iterator(); 57 while (it.hasNext()) { 58 if (!selectedWays.contains(it.next())) 59 it.remove(); 60 } 61 } 62 46 63 Iterator<Way> it = refs.iterator(); 47 64 while (it.hasNext()) { 48 if(!selectedWays.contains(it.next())) 65 Way w = it.next(); 66 if (w.isDeleted() || w.isIncomplete() || !w.isInnerNode(node)) 49 67 it.remove(); 50 68 } 69 if (refs.size() == 1) { 70 if (splitWays.containsKey(refs.get(0))) 71 splitWays.get(refs.get(0)).add(node); 72 else { 73 List<Node> nodes = new ArrayList<>(1); 74 nodes.add(node); 75 splitWays.put(refs.get(0), nodes); 76 } 77 } else if (refs.size() > 1) { 78 new Notification( 79 tr("There are several ways containing one of the splitting nodes. Select ways participating in this operation.") 80 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 81 return; 82 } 51 83 } 52 53 Iterator<Way> it = refs.iterator();54 while (it.hasNext()) {55 Way w = it.next();56 if( w.isDeleted() || w.isIncomplete() || !w.isInnerNode(node) )57 it.remove();58 }59 if( refs.size() == 1 ) {60 if( splitWays.containsKey(refs.get(0)) )61 splitWays.get(refs.get(0)).add(node);62 else {63 List<Node> nodes = new ArrayList<>(1);64 nodes.add(node);65 splitWays.put(refs.get(0), nodes);66 }67 } else if( refs.size() > 1 ) {68 new Notification(69 tr("There are several ways containing one of the splitting nodes. Select ways participating in this operation.")70 ).setIcon(JOptionPane.WARNING_MESSAGE).show();71 return;72 }73 }74 84 } 75 85 76 for (Way splitWay : splitWays.keySet()86 for (Way splitWay : splitWays.keySet()) { 77 87 List<List<Node>> wayChunks = SplitWayAction.buildSplitChunks(splitWay, splitWays.get(splitWay)); 78 if (wayChunks != null88 if (wayChunks != null) { 79 89 List<OsmPrimitive> sel = new ArrayList<>(selectedWays.size()); 80 90 sel.addAll(selectedWays); … … 84 94 } 85 95 86 if (!list.isEmpty()96 if (!list.isEmpty()) { 87 97 Main.main.undoRedo.add(list.size() == 1 ? list.get(0) : new SequenceCommand(TITLE, list)); 88 98 getLayerManager().getEditDataSet().clearSelection(); … … 96 106 97 107 @Override 98 protected void updateEnabledState( 108 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 99 109 boolean ok = false; 100 if( selection != null ) 101 for( OsmPrimitive p : selection ) { 102 if( p instanceof Way ) 103 ok = true; 104 else { 105 ok = false; 106 break; 110 if (selection != null) 111 for (OsmPrimitive p : selection) { 112 if (p instanceof Way) 113 ok = true; 114 else { 115 ok = false; 116 break; 117 } 107 118 } 108 }109 119 setEnabled(ok); 110 120 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SymmetryAction.java
r32333 r32410 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.actions; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;6 6 7 7 import java.awt.event.ActionEvent; … … 23 23 import org.openstreetmap.josm.data.osm.Way; 24 24 import org.openstreetmap.josm.gui.Notification; 25 26 25 import org.openstreetmap.josm.tools.Shortcut; 27 26 … … 32 31 * 33 32 * @author Alexei Kasatkin, based on much copy&Paste from other MirrorAction :) 34 */ 33 */ 35 34 public final class SymmetryAction extends JosmAction { 36 35 … … 49 48 Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getSelected(); 50 49 HashSet<Node> nodes = new HashSet<>(); 51 EastNorth p1 =null,p2=null;52 50 EastNorth p1 = null, p2 = null; 51 53 52 for (OsmPrimitive osm : sel) { 54 53 if (osm instanceof Node) { 55 if (p1 ==null) p1=((Node)osm).getEastNorth(); else56 if (p2==null) p2=((Node)osm).getEastNorth(); else57 nodes.add((Node)osm); 54 if (p1 == null) p1 = ((Node) osm).getEastNorth(); else 55 if (p2 == null) p2 = ((Node) osm).getEastNorth(); else 56 nodes.add((Node) osm); 58 57 } 59 58 } 60 59 for (OsmPrimitive osm : sel) { 61 60 if (osm instanceof Way) { 62 nodes.addAll(((Way)osm).getNodes()); 61 nodes.addAll(((Way) osm).getNodes()); 63 62 } 64 63 } 65 66 if (p1 ==null || p2==null || nodes.size() < 1) {64 65 if (p1 == null || p2 == null || nodes.size() < 1) { 67 66 new Notification( 68 67 tr("Please select at least two nodes for symmetry axis and something else to mirror.") 69 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 68 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 70 69 return; 71 70 } 72 71 73 double ne,nn,l,e0,n0; 74 e0=p1.east(); n0=p1.north(); 75 ne = -(p2.north()-p1.north()); nn = (p2.east()-p1.east()); 76 l = Math.hypot(ne,nn); 72 double ne, nn, l, e0, n0; 73 e0 = p1.east(); 74 n0 = p1.north(); 75 ne = -(p2.north() - p1.north()); 76 nn = (p2.east() - p1.east()); 77 l = Math.hypot(ne, nn); 77 78 ne /= l; nn /= l; // normal unit vector 78 79 79 80 Collection<Command> cmds = new LinkedList<>(); 80 81 … … 83 84 double pr = (c.east()-e0)*ne + (c.north()-n0)*nn; 84 85 //pr=10; 85 cmds.add(new MoveCommand(n, -2*ne*pr, -2*nn*pr 86 cmds.add(new MoveCommand(n, -2*ne*pr, -2*nn*pr)); 86 87 } 87 88 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagBufferAction.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.actions; 2 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.event.ActionEvent; 7 import java.awt.event.KeyEvent; 8 import java.util.ArrayList; 9 import java.util.Collection; 10 import java.util.HashMap; 11 import java.util.HashSet; 12 import java.util.List; 13 import java.util.Map; 14 import java.util.Set; 15 3 16 import org.openstreetmap.josm.Main; 4 import org.openstreetmap.josm.command.*; 5 import java.util.*; 6 import java.awt.event.KeyEvent; 17 import org.openstreetmap.josm.actions.JosmAction; 18 import org.openstreetmap.josm.command.ChangePropertyCommand; 19 import org.openstreetmap.josm.command.Command; 20 import org.openstreetmap.josm.command.SequenceCommand; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 22 import org.openstreetmap.josm.tools.Predicate; 8 23 import org.openstreetmap.josm.tools.Shortcut; 9 import java.awt.event.ActionEvent;10 import org.openstreetmap.josm.actions.JosmAction;11 import org.openstreetmap.josm.data.osm.OsmPrimitive;12 24 import org.openstreetmap.josm.tools.Utils; 13 import static org.openstreetmap.josm.tools.I18n.tr;14 25 15 26 /** … … 35 46 public TagBufferAction() { 36 47 super(TITLE, "dumbutils/tagbuffer", tr("Pastes tags of previously selected object(s)"), 37 Shortcut.registerShortcut("tools:tagbuffer", tr("Tool: {0}", tr("Copy tags from previous selection")), KeyEvent.VK_R, Shortcut.SHIFT) 38 , true, false); 48 Shortcut.registerShortcut("tools:tagbuffer", tr("Tool: {0}", tr("Copy tags from previous selection")), 49 KeyEvent.VK_R, Shortcut.SHIFT), 50 true, false); 39 51 // The fields are not initialized while the super constructor is running, so we have to call this afterwards: 40 52 installAdapters(); … … 42 54 43 55 @Override 44 public void actionPerformed( 56 public void actionPerformed(ActionEvent e) { 45 57 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 46 if (selection.isEmpty()58 if (selection.isEmpty()) 47 59 return; 48 60 49 61 List<Command> commands = new ArrayList<>(); 50 for (String key : tags.keySet()62 for (String key : tags.keySet()) { 51 63 String value = tags.get(key); 52 64 boolean foundNew = false; 53 for (OsmPrimitive p : selection54 if (!p.hasKey(key) || !p.get(key).equals(value)65 for (OsmPrimitive p : selection) { 66 if (!p.hasKey(key) || !p.get(key).equals(value)) { 55 67 foundNew = true; 56 68 break; 57 69 } 58 70 } 59 if (foundNew71 if (foundNew) 60 72 commands.add(new ChangePropertyCommand(selection, key, value)); 61 73 } 62 63 if (!commands.isEmpty()74 75 if (!commands.isEmpty()) 64 76 Main.main.undoRedo.add(new SequenceCommand(TITLE, commands)); 65 77 } … … 67 79 @Override 68 80 protected void updateEnabledState() { 69 if (getLayerManager().getEditDataSet() == null81 if (getLayerManager().getEditDataSet() == null) { 70 82 setEnabled(false); 71 if (selectionBuf != null83 if (selectionBuf != null) 72 84 selectionBuf.clear(); 73 } 85 } else 74 86 updateEnabledState(getLayerManager().getEditDataSet().getSelected()); 75 87 } 76 88 77 89 @Override 78 protected void updateEnabledState( 90 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 79 91 // selection changed => check if selection is completely different from before 80 92 boolean foundOld = false; 81 if (selection != null82 for (OsmPrimitive p : selectionBuf83 if (selection.contains(p)93 if (selection != null) { 94 for (OsmPrimitive p : selectionBuf) { 95 if (selection.contains(p)) { 84 96 foundOld = true; 85 97 break; … … 92 104 selectionBuf.clear(); 93 105 } 94 if (!foundOld106 if (!foundOld) { 95 107 // selection has completely changed, remember tags 96 108 tags.clear(); 97 109 tags.putAll(currentTags); 98 110 } 99 if (getLayerManager().getEditDataSet() != null)111 if (getLayerManager().getEditDataSet() != null) 100 112 rememberSelectionTags(); 101 113 … … 105 117 private void rememberSelectionTags() { 106 118 // Fix #8350 - only care about tagged objects 107 final Collection<OsmPrimitive> selectedTaggedObjects = Utils.filter(getLayerManager().getEditDataSet().getSelected(), IS_TAGGED_PREDICATE); 108 if( !selectedTaggedObjects.isEmpty() ) { 119 final Collection<OsmPrimitive> selectedTaggedObjects = Utils.filter( 120 getLayerManager().getEditDataSet().getSelected(), IS_TAGGED_PREDICATE); 121 if (!selectedTaggedObjects.isEmpty()) { 109 122 currentTags.clear(); 110 123 Set<String> bad = new HashSet<>(); 111 for (OsmPrimitive p : selectedTaggedObjects112 if (currentTags.isEmpty()113 for (String key : p.keySet())124 for (OsmPrimitive p : selectedTaggedObjects) { 125 if (currentTags.isEmpty()) { 126 for (String key : p.keySet()) { 114 127 currentTags.put(key, p.get(key)); 128 } 115 129 } else { 116 for (String key : p.keySet())117 if (!currentTags.containsKey(key) || !currentTags.get(key).equals(p.get(key))130 for (String key : p.keySet()) { 131 if (!currentTags.containsKey(key) || !currentTags.get(key).equals(p.get(key))) 118 132 bad.add(key); 119 for( String key : currentTags.keySet() ) 120 if( !p.hasKey(key) ) 133 } 134 for (String key : currentTags.keySet()) { 135 if (!p.hasKey(key)) 121 136 bad.add(key); 137 } 122 138 } 123 139 } 124 for (String key : bad)140 for (String key : bad) { 125 141 currentTags.remove(key); 142 } 126 143 } 127 144 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagSourceAction.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.actions; 2 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.event.ActionEvent; 7 import java.awt.event.KeyEvent; 8 import java.util.Collection; 9 import java.util.HashSet; 10 import java.util.Set; 11 3 12 import org.openstreetmap.josm.Main; 4 import org.openstreetmap.josm. command.*;5 import java.util.*;6 import java.awt.event.KeyEvent;13 import org.openstreetmap.josm.actions.JosmAction; 14 import org.openstreetmap.josm.command.ChangePropertyCommand; 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 16 import org.openstreetmap.josm.tools.Shortcut; 8 import java.awt.event.ActionEvent;9 import org.openstreetmap.josm.actions.JosmAction;10 import org.openstreetmap.josm.data.osm.OsmPrimitive;11 import static org.openstreetmap.josm.tools.I18n.tr;12 17 13 18 /** … … 24 29 public TagSourceAction() { 25 30 super(TITLE, "dumbutils/sourcetag", tr("Add remembered source tag"), 26 Shortcut.registerShortcut("tools:sourcetag", tr("Tool: {0}", tr("Add Source Tag")), KeyEvent.VK_S, Shortcut.ALT_CTRL) 27 ,true, false);31 Shortcut.registerShortcut("tools:sourcetag", tr("Tool: {0}", tr("Add Source Tag")), KeyEvent.VK_S, Shortcut.ALT_CTRL), 32 true, false); 28 33 source = Main.pref.get("sourcetag.value"); 29 34 // The fields are not initialized while the super constructor is running, so we have to call this afterwards: … … 32 37 33 38 @Override 34 public void actionPerformed( 39 public void actionPerformed(ActionEvent e) { 35 40 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 36 if (selection.isEmpty() || source == null || source.length() == 041 if (selection.isEmpty() || source == null || source.length() == 0) 37 42 return; 38 43 … … 42 47 @Override 43 48 protected void updateEnabledState() { 44 if (getLayerManager().getEditDataSet() == null49 if (getLayerManager().getEditDataSet() == null) { 45 50 setEnabled(false); 46 if (selectionBuf != null51 if (selectionBuf != null) 47 52 selectionBuf.clear(); 48 } 53 } else 49 54 updateEnabledState(getLayerManager().getEditDataSet().getSelected()); 50 55 } 51 56 52 57 @Override 53 protected void updateEnabledState( 54 if (selection == null || selection.isEmpty()58 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 59 if (selection == null || selection.isEmpty()) { 55 60 selectionBuf.clear(); 56 61 clickedTwice = false; … … 59 64 } 60 65 61 if (selectionBuf.size() == selection.size() && selectionBuf.containsAll(selection)62 if (!clickedTwice66 if (selectionBuf.size() == selection.size() && selectionBuf.containsAll(selection)) { 67 if (!clickedTwice) 63 68 clickedTwice = true; 64 69 else { 65 70 // tags may have been changed, get the source 66 71 String newSource = null; 67 for (OsmPrimitive p : selection72 for (OsmPrimitive p : selection) { 68 73 String value = p.get("source"); 69 if (value != null && newSource == null74 if (value != null && newSource == null) 70 75 newSource = value; 71 else if (value != null ? !value.equals(newSource) : newSource != null76 else if (value != null ? !value.equals(newSource) : newSource != null) { 72 77 newSource = ""; 73 78 break; 74 79 } 75 80 } 76 if (newSource != null && newSource.length() > 0 && !newSource.equals(source)81 if (newSource != null && newSource.length() > 0 && !newSource.equals(source)) { 77 82 source = newSource; 78 83 Main.pref.put("sourcetag.value", source); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/UnGlueRelationAction.java
r32333 r32410 1 // License: GPL v2 or later. Copyright 2010 by Kalle Lampila and others 2 // See LICENSE file for details. 1 // License: GPL. For details, see LICENSE file. 3 2 package org.openstreetmap.josm.plugins.utilsplugin2.actions; 4 3 … … 39 38 public UnGlueRelationAction() { 40 39 super(tr("UnGlue Relation"), "ungluerelations", tr("Duplicate nodes, ways and relations that are used by multiple relations."), 41 Shortcut.registerShortcut("tools:ungluerelation", tr("Tool: {0}", tr("UnGlue Relations")), KeyEvent.VK_G, Shortcut.ALT_SHIFT ), true); 40 Shortcut.registerShortcut("tools:ungluerelation", tr("Tool: {0}", tr("UnGlue Relations")), KeyEvent.VK_G, Shortcut.ALT_SHIFT), 41 true); 42 42 putValue("help", ht("/Action/UnGlueRelation")); 43 43 } … … 62 62 OsmPrimitive newp; 63 63 switch(p.getType()) { 64 case NODE: newp = new Node((Node)p, true); break; 65 case WAY: newp = new Way((Way)p, true); break; 66 case RELATION: newp = new Relation((Relation)p, true); break; 64 case NODE: newp = new Node((Node) p, true); break; 65 case WAY: newp = new Way((Way) p, true); break; 66 case RELATION: newp = new Relation((Relation) p, true); break; 67 67 default: throw new AssertionError(); 68 } 68 } 69 69 newPrimitives.add(newp); 70 70 cmds.add(new AddCommand(newp)); … … 76 76 } 77 77 78 if (newPrimitives.isEmpty() 78 if (newPrimitives.isEmpty()) { 79 79 // error message nothing to do 80 } 81 else { 80 } else { 82 81 Main.main.undoRedo.add(new SequenceCommand(tr("Unglued Relations"), cmds)); 83 82 //Set selection all primiteves (new and old) -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/command/ChangeRelationMemberCommand.java
r30737 r32410 1 // License: GPL v2 or later. See LICENSE filefor details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.command; 3 3 … … 44 44 relation.setMembers(newrms); 45 45 } 46 46 47 47 @Override 48 48 public boolean executeCommand() { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/curves/CircleArcMaker.java
r30737 r32410 1 // License: GPL. Copyright 2011 by Ole Jørgen Brønner1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.curves; 3 3 … … 21 21 import org.openstreetmap.josm.data.osm.Way; 22 22 23 public class CircleArcMaker { 23 public final class CircleArcMaker { 24 25 private CircleArcMaker() { 26 // Hide default constructor for utilities classes 27 } 28 24 29 public static Collection<Command> doCircleArc(List<Node> selectedNodes, List<Way> selectedWays, int angleSeparation) { 25 30 Collection<Command> cmds = new LinkedList<>(); … … 95 100 } 96 101 // Fix #7341. Find the first way having all nodes in common to sort them in its nodes order 97 List<Node> consideredNodes = Arrays.asList(new Node[]{n1, n2,n3});102 List<Node> consideredNodes = Arrays.asList(new Node[]{n1, n2, n3}); 98 103 for (Way w : selectedWays) { 99 104 final List<Node> nodes = w.getNodes(); … … 111 116 } 112 117 } 113 118 114 119 for (Node n : consideredNodes) { 115 120 targetWays.addAll(OsmPrimitive.getFilteredList(n.getReferrers(), Way.class)); … … 133 138 List<Node> arcNodes = new ArrayList<>(points.size()); 134 139 arcNodes.add(n1); 135 { 136 int i = 1; 137 for (EastNorth p : slice(points, 1, -2)) { 138 // if (p == p2) { 139 if (i == p2Index.value) { 140 Node n2new = new Node(n2); 141 n2new.setEastNorth(p); 142 arcNodes.add(n2); // add the original n2, or else we can't find it in the target ways 143 cmds.add(new ChangeCommand(n2, n2new)); 144 } else { 145 Node n = new Node(p); 146 arcNodes.add(n); 147 cmds.add(new AddCommand(n)); 148 } 149 i++; 150 } 140 int i = 1; 141 for (EastNorth p : slice(points, 1, -2)) { 142 if (i == p2Index.value) { 143 Node n2new = new Node(n2); 144 n2new.setEastNorth(p); 145 arcNodes.add(n2); // add the original n2, or else we can't find it in the target ways 146 cmds.add(new ChangeCommand(n2, n2new)); 147 } else { 148 Node n = new Node(p); 149 arcNodes.add(n); 150 cmds.add(new AddCommand(n)); 151 } 152 i++; 151 153 } 152 154 arcNodes.add(n3); 153 155 154 Node[] anchorNodes = { 156 Node[] anchorNodes = {n1, n2, n3}; 155 157 //// "Fuse" the arc with all target ways 156 158 fuseArc(anchorNodes, arcNodes, targetWays, cmds); … … 359 361 return a; 360 362 } 363 361 364 public static class ReturnValue<T> { 362 365 public T value; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/curves/CurveAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Ole Jørgen Brønner1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.curves; 3 3 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/ChooseURLAction.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.customurl; 2 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 3 6 import java.awt.GridBagLayout; 7 import java.awt.event.ActionEvent; 4 8 import java.util.List; 5 import javax.swing.JPanel; 6 import javax.swing.event.ListSelectionEvent; 7 import org.openstreetmap.josm.gui.ExtendedDialog; 8 import org.openstreetmap.josm.tools.GBC; 9 import org.openstreetmap.josm.Main; 10 import java.awt.event.ActionEvent; 9 11 10 import javax.swing.JCheckBox; 12 11 import javax.swing.JLabel; 13 12 import javax.swing.JList; 13 import javax.swing.JPanel; 14 14 import javax.swing.JTextField; 15 15 import javax.swing.ListSelectionModel; 16 import javax.swing.event.ListSelectionEvent; 16 17 import javax.swing.event.ListSelectionListener; 18 19 import org.openstreetmap.josm.Main; 17 20 import org.openstreetmap.josm.actions.JosmAction; 18 import static org.openstreetmap.josm.tools.I18n.tr; 21 import org.openstreetmap.josm.gui.ExtendedDialog; 22 import org.openstreetmap.josm.tools.GBC; 19 23 20 24 public class ChooseURLAction extends JosmAction { 21 25 22 26 public ChooseURLAction() { 23 super(tr("Select custom URL"), "selecturl", tr("Select custom URL"), null,true,true);27 super(tr("Select custom URL"), "selecturl", tr("Select custom URL"), null, true, true); 24 28 } 25 29 … … 33 37 setEnabled(getLayerManager().getEditDataSet() != null); 34 38 } 35 39 36 40 public static void showConfigDialog(final boolean fast) { 37 41 JPanel all = new JPanel(new GridBagLayout()); 38 42 39 43 List<String> items = URLList.getURLList(); 40 44 String addr = URLList.getSelectedURL(); 41 int n =items.size()/2=-1;42 final String names[] =new String[n];43 final String vals[] =new String[n];44 for (int i =0;i<n;i++) {45 names[i] =items.get(i*2);46 vals[i] =items.get(i*2+1);47 if (vals[i].equals(addr)) idxToSelect =i;45 int n = items.size()/2, idxToSelect = -1; 46 final String[] names = new String[n]; 47 final String[] vals = new String[n]; 48 for (int i = 0; i < n; i++) { 49 names[i] = items.get(i*2); 50 vals[i] = items.get(i*2+1); 51 if (vals[i].equals(addr)) idxToSelect = i; 48 52 } 49 final JLabel label1 =new JLabel(tr("Please select one of custom URLs (configured in Preferences)"));50 final JList<String> list1 =new JList<>(names);51 final JTextField editField =new JTextField();52 final JCheckBox check1 =new JCheckBox(tr("Ask every time"));53 53 final JLabel label1 = new JLabel(tr("Please select one of custom URLs (configured in Preferences)")); 54 final JList<String> list1 = new JList<>(names); 55 final JTextField editField = new JTextField(); 56 final JCheckBox check1 = new JCheckBox(tr("Ask every time")); 57 54 58 final ExtendedDialog dialog = new ExtendedDialog(Main.parent, 55 59 tr("Configure custom URL"), 56 new String[] {tr("OK"),tr("Cancel") ,}57 ); 60 new String[] {tr("OK"), tr("Cancel")} 61 ); 58 62 list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 59 63 list1.addListSelectionListener(new ListSelectionListener() { 60 64 @Override 61 65 public void valueChanged(ListSelectionEvent e) { 62 int idx =list1.getSelectedIndex();63 if (idx >=0) editField.setText(vals[idx]);66 int idx = list1.getSelectedIndex(); 67 if (idx >= 0) editField.setText(vals[idx]); 64 68 } 65 69 }); 66 70 list1.setSelectedIndex(idxToSelect); 67 check1.setSelected(Main.pref.getBoolean("utilsplugin2.askurl",false)); 68 71 check1.setSelected(Main.pref.getBoolean("utilsplugin2.askurl", false)); 72 69 73 editField.setEditable(false); 70 71 all.add(label1,GBC.eop().fill(GBC.HORIZONTAL).insets(15, 5,15,0));72 all.add(list1,GBC.eop().fill(GBC.HORIZONTAL).insets(5, 5,0,0));73 all.add(editField,GBC.eop().fill(GBC.HORIZONTAL).insets(5, 5,0,0));74 all.add(check1,GBC.eop().fill(GBC.HORIZONTAL).insets(5, 5,0,0));75 76 74 75 all.add(label1, GBC.eop().fill(GBC.HORIZONTAL).insets(15, 5, 15, 0)); 76 all.add(list1, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 5, 0, 0)); 77 all.add(editField, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 5, 0, 0)); 78 all.add(check1, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 5, 0, 0)); 79 80 77 81 dialog.setContent(all, false); 78 dialog.setButtonIcons(new String[] {"ok.png","cancel.png" ,});82 dialog.setButtonIcons(new String[] {"ok.png", "cancel.png"}); 79 83 dialog.setDefaultButton(1); 80 84 dialog.showDialog(); 81 85 82 86 int idx = list1.getSelectedIndex(); 83 if (dialog.getValue() ==1 && idx >=0) {84 URLList.select(vals[idx]); 85 Main.pref.put("utilsplugin2.askurl", check1.isSelected()); 87 if (dialog.getValue() == 1 && idx >= 0) { 88 URLList.select(vals[idx]); 89 Main.pref.put("utilsplugin2.askurl", check1.isSelected()); 86 90 } 87 91 } 88 89 90 91 92 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/OpenPageAction.java
r32333 r32410 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.customurl; 3 3 4 import java.io.UnsupportedEncodingException;4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;7 6 8 7 import java.awt.event.ActionEvent; 9 8 import java.awt.event.KeyEvent; 9 import java.io.UnsupportedEncodingException; 10 10 import java.net.URLEncoder; 11 11 import java.util.Collection; 12 13 12 import java.util.regex.Matcher; 14 15 13 import java.util.regex.Pattern; 16 14 … … 30 28 * 31 29 * @author Alexei Kasatkin, based on much copy&Paste from other MirrorAction :) 32 */ 30 */ 33 31 public final class OpenPageAction extends JosmAction { 34 32 35 33 public OpenPageAction() { 36 34 super(tr("Open custom URL"), "openurl", 37 35 tr("Opens specified URL browser"), 38 36 Shortcut.registerShortcut("tools:openurl", tr("Tool: {0}", tr("Open custom URL")), 39 KeyEvent.VK_H, Shortcut.SHIFT), true); 37 KeyEvent.VK_H, Shortcut.SHIFT), true); 40 38 putValue("help", ht("/Action/OpenPage")); 41 39 } … … 44 42 public void actionPerformed(ActionEvent e) { 45 43 Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getSelected(); 46 OsmPrimitive p =null;47 if (sel.size() >=1) {48 p =sel.iterator().next();44 OsmPrimitive p = null; 45 if (sel.size() >= 1) { 46 p = sel.iterator().next(); 49 47 } 50 51 if (Main.pref.getBoolean("utilsplugin2.askurl", false)==true)48 49 if (Main.pref.getBoolean("utilsplugin2.askurl", false) == true) 52 50 ChooseURLAction.showConfigDialog(true); 53 54 //lat = p.getBBox().getTopLeft().lat(); 55 //lon = p.getBBox().getTopLeft().lon(); 51 56 52 LatLon center = Main.map.mapView.getLatLon(Main.map.mapView.getWidth()/2, Main.map.mapView.getHeight()/2); 57 58 String addr = 53 54 String addr = URLList.getSelectedURL(); 59 55 Pattern pat = Pattern.compile("\\{([^\\}]*)\\}"); 60 56 Matcher m = pat.matcher(addr); 61 String val,key; 62 String keys[]=new String[100],vals[]=new String[100];63 int i =0;57 String val, key; 58 String[] keys = new String[100], vals = new String[100]; 59 int i = 0; 64 60 try { 65 while (m.find()) { 66 key=m.group(1); val=null; 67 if (key.equals("#id")) { 68 if (p!=null) val=Long.toString(p.getId()); 69 } else if (key.equals("#type")) { 70 if (p!=null) val = OsmPrimitiveType.from(p).getAPIName(); 71 } else if (key.equals("#lat")) { 72 val = Double.toString(center.lat()); 73 } else if (key.equals("#lon")) { 74 val = Double.toString(center.lon()); 75 } else if (key.equals("#zoom")) { 76 val = Integer.toString(OsmUrlToBounds.getZoom(Main.map.mapView.getRealBounds())); 61 while (m.find()) { 62 key = m.group(1); val = null; 63 if (key.equals("#id")) { 64 if (p != null) val = Long.toString(p.getId()); 65 } else if (key.equals("#type")) { 66 if (p != null) val = OsmPrimitiveType.from(p).getAPIName(); 67 } else if (key.equals("#lat")) { 68 val = Double.toString(center.lat()); 69 } else if (key.equals("#lon")) { 70 val = Double.toString(center.lon()); 71 } else if (key.equals("#zoom")) { 72 val = Integer.toString(OsmUrlToBounds.getZoom(Main.map.mapView.getRealBounds())); 73 } else { 74 if (p != null) { 75 val = p.get(key); 76 if (val != null) val = URLEncoder.encode(p.get(key), "UTF-8"); else return; 77 } 78 } 79 keys[i] = m.group(); 80 if (val != null) vals[i] = val; 81 else vals[i] = ""; 82 i++; 77 83 } 78 else {79 if (p!=null) {80 val =p.get(key);81 if (val!=null) val =URLEncoder.encode(p.get(key), "UTF-8"); else return;82 }83 }84 keys[i]=m.group();85 if (val!=null) vals[i]=val;86 else vals[i]="";87 i++;88 }89 84 } catch (UnsupportedEncodingException ex) { 90 85 Main.error(ex, "Encoding error"); 91 86 return; 92 87 } 93 for (int j =0;j<i;j++){94 addr = addr.replace(keys[j],vals[j]); 88 for (int j = 0; j < i; j++) { 89 addr = addr.replace(keys[j], vals[j]); 95 90 } 96 91 try { … … 99 94 Main.error(ex, "Can not open URL " + addr); 100 95 } 101 //Collection<Command> cmds = new LinkedList<Command>();102 103 //cmds.add(new MoveCommand(n, -2*ne*pr, -2*nn*pr ));104 //Main.main.undoRedo.add(new SequenceCommand(tr("Symmetry"), cmds));105 96 } 106 97 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/URLList.java
r31153 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.customurl; 2 3 … … 14 15 import org.openstreetmap.josm.plugins.utilsplugin2.UtilsPlugin2; 15 16 16 public class URLList { 17 public final class URLList { 17 18 public static final String defaultURL = "http://osm.mapki.com/history/{#type}.php?id={#id}"; 19 20 private URLList() { 21 // Hide default constructor for utilities classes 22 } 18 23 19 24 public static String getSelectedURL() { … … 21 26 return Main.pref.get("utilsplugin2.customurl", defaultURL); 22 27 } 28 23 29 public static void select(String url) { 24 Main.pref.put("utilsplugin2.customurl",url); 30 Main.pref.put("utilsplugin2.customurl", url); 25 31 } 32 26 33 public static List<String> resetURLList() { 27 List<String> items =new ArrayList<>();34 List<String> items = new ArrayList<>(); 28 35 items.add("Wikipedia"); 29 36 items.add("https://en.wikipedia.org/w/index.php?search={name}&fulltext=Search"); … … 38 45 items.add("Browse element [demo, =Ctrl-Shift-I]"); 39 46 items.add("https://www.openstreetmap.org/{#type}/{#id}"); 40 Main.pref.putCollection("utilsplugin2.urlHistory",items); 41 Main.pref.put("utilsplugin2.customurl",items.get(9)); 47 Main.pref.putCollection("utilsplugin2.urlHistory", items); 48 Main.pref.put("utilsplugin2.customurl", items.get(9)); 42 49 return items; 43 50 } … … 45 52 public static List<String> getURLList() { 46 53 List<String> items = (List<String>) Main.pref.getCollection("utilsplugin2.urlHistory"); 47 if (items ==null || items.isEmpty()) {54 if (items == null || items.isEmpty()) { 48 55 resetURLList(); 49 items =(List<String>) Main.pref.getCollection("utilsplugin2.urlHistory");56 items = (List<String>) Main.pref.getCollection("utilsplugin2.urlHistory"); 50 57 } 51 58 return items; … … 53 60 54 61 public static void updateURLList(List<String> lst) { 55 Main.pref.putCollection("utilsplugin2.urlHistory",lst); 62 Main.pref.putCollection("utilsplugin2.urlHistory", lst); 56 63 try { 57 64 Main.pref.save(); … … 62 69 63 70 public static List<String> loadURLList() { 64 ArrayList<String> items =new ArrayList<>();65 BufferedReader fr =null;71 ArrayList<String> items = new ArrayList<>(); 72 BufferedReader fr = null; 66 73 try { 67 68 69 70 null) items.add(s);74 File f = new File(UtilsPlugin2.getInstance().getPluginDir(), "customurl.txt"); 75 fr = new BufferedReader(new FileReader(f)); 76 String s; 77 while ((s = fr.readLine()) != null) items.add(s); 71 78 } catch (IOException e) { 72 79 e.printStackTrace(); 73 80 } finally { 74 try { if (fr!=null) fr.close(); } catch (Exception e) {} 81 try { 82 if (fr != null) 83 fr.close(); 84 } catch (Exception e) { 85 Main.warn(e); 86 } 75 87 } 76 88 return items; … … 79 91 public static void saveURLList(List<String> items) { 80 92 File f = new File(UtilsPlugin2.getInstance().getPluginDir(), "customurl.txt"); 81 PrintWriter fw =null;93 PrintWriter fw = null; 82 94 try { 83 95 f.getParentFile().mkdirs(); 84 =new PrintWriter(f);85 86 87 96 fw = new PrintWriter(f); 97 for (String s : items) { 98 fw.println(s); 99 } 88 100 } catch (IOException e) { 89 101 e.printStackTrace(); 90 102 } finally { 91 try { if (fw!=null) fw.close(); } catch (Exception e) {} 103 try { 104 if (fw != null) 105 fw.close(); 106 } catch (Exception e) { 107 Main.warn(e); 108 } 92 109 } 93 110 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/UtilsPluginPreferences.java
r30737 r32410 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.customurl; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.GridBagLayout; 4 7 import java.awt.event.ActionEvent; 8 import java.awt.event.ActionListener; 9 import java.util.ArrayList; 10 import java.util.List; 11 5 12 import javax.swing.JButton; 6 import java.util.List; 13 import javax.swing.JLabel; 14 import javax.swing.JPanel; 15 import javax.swing.JTable; 16 import javax.swing.ListSelectionModel; 17 import javax.swing.event.TableModelEvent; 18 import javax.swing.event.TableModelListener; 19 import javax.swing.table.DefaultTableModel; 7 20 import javax.swing.table.TableModel; 8 import javax.swing.JTable; 9 import javax.swing.JLabel; 10 import java.awt.GridBagLayout; 11 import java.util.ArrayList; 12 import javax.swing.event.TableModelEvent; 21 22 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting; 23 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 13 24 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 14 25 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 15 import java.awt.event.ActionListener;16 import javax.swing.JPanel;17 import javax.swing.ListSelectionModel;18 import javax.swing.event.TableModelListener;19 import javax.swing.table.DefaultTableModel;20 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;21 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;22 26 import org.openstreetmap.josm.tools.GBC; 23 27 24 import static org.openstreetmap.josm.tools.I18n.*;25 26 28 public class UtilsPluginPreferences extends DefaultTabPreferenceSetting { 27 HistoryComboBox combo1 =new HistoryComboBox();29 HistoryComboBox combo1 = new HistoryComboBox(); 28 30 JTable table; 29 31 JButton resetButton; … … 40 42 41 43 URLList.getSelectedURL(); 42 table =new JTable(new DefaultTableModel(null,new String[]{"Title","URL"}));44 table = new JTable(new DefaultTableModel(null, new String[]{"Title", "URL"})); 43 45 44 46 List<String> items = URLList.getURLList(); … … 77 79 + " Your can manually load settings from file <b>customurl.txt</b> in JOSM folder")); 78 80 79 all.add(new JLabel(tr("Custom URL configuration")),GBC.std().insets(5, 10,0,0));80 all.add(resetButton,GBC.std().insets(25, 10,0,0));81 all.add(loadButton,GBC.std().insets(25, 10,0,0));82 all.add(saveButton,GBC.eol().insets(25, 10,0,0));83 all.add(help,GBC.eop().insets(5, 10,0,0));81 all.add(new JLabel(tr("Custom URL configuration")), GBC.std().insets(5, 10, 0, 0)); 82 all.add(resetButton, GBC.std().insets(25, 10, 0, 0)); 83 all.add(loadButton, GBC.std().insets(25, 10, 0, 0)); 84 all.add(saveButton, GBC.eol().insets(25, 10, 0, 0)); 85 all.add(help, GBC.eop().insets(5, 10, 0, 0)); 84 86 85 87 table.getColumnModel().getColumn(0).setPreferredWidth(150); … … 92 94 int row = e.getFirstRow(); 93 95 int column = e.getColumn(); 94 DefaultTableModel model = (DefaultTableModel) (e.getSource());95 if (row <0|| column<0) return;96 String data = (String)model.getValueAt(row, column); 97 if (data !=null && data.length()>0 && row==model.getRowCount()-1)98 model.addRow(new String[]{"",""}); 96 DefaultTableModel model = (DefaultTableModel) e.getSource(); 97 if (row < 0 || column < 0) return; 98 String data = (String) model.getValueAt(row, column); 99 if (data != null && data.length() > 0 && row == model.getRowCount()-1) 100 model.addRow(new String[]{"", ""}); 99 101 } 100 102 }); 101 all.add(table,GBC.eop().fill()); 103 all.add(table, GBC.eop().fill()); 102 104 createPreferenceTabWithScrollPane(gui, all); 103 105 } 104 106 105 107 private void fillRows(List<String> items) { 106 if (items ==null) return;107 int p =0;108 if (items == null) return; 109 int p = 0; 108 110 String name, url; 109 111 DefaultTableModel model = (DefaultTableModel) table.getModel(); 110 112 model.setRowCount(0); 111 int n =items.size();113 int n = items.size(); 112 114 while (true) { 113 if (p >=n) break;115 if (p >= n) break; 114 116 name = items.get(p); 115 117 p++; 116 if (p >=n) break;118 if (p >= n) break; 117 119 url = items.get(p); 118 120 p++; 119 model.addRow(new String[]{name,url}); 121 model.addRow(new String[]{name, url}); 120 122 } 121 model.addRow(new String[]{"",""}); 123 model.addRow(new String[]{"", ""}); 122 124 } 123 125 … … 134 136 TableModel model = (table.getModel()); 135 137 String v; 136 ArrayList<String> lst =new ArrayList<>();137 int n =model.getRowCount();138 for (int i =0;i<n;i++) {139 v =(String) model.getValueAt(i, 0);140 if (v.length() ==0) continue;138 ArrayList<String> lst = new ArrayList<>(); 139 int n = model.getRowCount(); 140 for (int i = 0; i < n; i++) { 141 v = (String) model.getValueAt(i, 0); 142 if (v.length() == 0) continue; 141 143 lst.add(v); 142 v =(String) model.getValueAt(i, 1);144 v = (String) model.getValueAt(i, 1); 143 145 lst.add(v); 144 146 } 145 int row =table.getSelectedRow();146 if (row !=-1) {147 v =(String) model.getValueAt(row, 1);147 int row = table.getSelectedRow(); 148 if (row != -1) { 149 v = (String) model.getValueAt(row, 1); 148 150 URLList.select(v); 149 151 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/latlon/LatLonAction.java
r32333 r32410 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.latlon; 3 3 … … 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 10 9 import java.util.Collection; 11 10 import java.util.LinkedList; 12 11 13 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.actions.JosmAction; 14 14 import org.openstreetmap.josm.command.AddCommand; 15 import org.openstreetmap.josm.command.Command; 15 16 import org.openstreetmap.josm.command.SequenceCommand; 16 import org.openstreetmap.josm.command.Command;17 17 import org.openstreetmap.josm.data.coor.LatLon; 18 18 import org.openstreetmap.josm.data.osm.Node; 19 19 import org.openstreetmap.josm.data.osm.Way; 20 20 import org.openstreetmap.josm.tools.Shortcut; 21 import org.openstreetmap.josm.actions.JosmAction;22 21 23 22 /** … … 47 46 48 47 dialog.showDialog(); 49 48 50 49 if (dialog.getValue() != 1) 51 50 return; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/latlon/LatLonDialog.java
r31651 r32410 18 18 19 19 import javax.swing.BorderFactory; 20 import javax.swing.ButtonGroup; 20 21 import javax.swing.JLabel; 21 22 import javax.swing.JPanel; 23 import javax.swing.JRadioButton; 24 import javax.swing.JScrollPane; 22 25 import javax.swing.JSeparator; 23 26 import javax.swing.JTabbedPane; 24 25 27 import javax.swing.JTextArea; 26 import javax.swing.JScrollPane;27 import javax.swing.ButtonGroup;28 import javax.swing.JRadioButton;29 30 28 import javax.swing.UIManager; 31 29 import javax.swing.event.ChangeEvent; … … 43 41 44 42 public class LatLonDialog extends ExtendedDialog { 45 private static final Color BG_COLOR_ERROR = new Color(255, 224,224);43 private static final Color BG_COLOR_ERROR = new Color(255, 224, 224); 46 44 47 45 public JTabbedPane tabs; … … 78 76 protected JPanel buildLatLon() { 79 77 JPanel pnl = new JPanel(new GridBagLayout()); 80 pnl.setBorder(BorderFactory.createEmptyBorder(5, 5,5,5));81 82 pnl.add(new JLabel(tr("Coordinates:")), GBC.std().insets(0, 10,5,0));83 84 taLatLon = new JTextArea(5,24); 78 pnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 79 80 pnl.add(new JLabel(tr("Coordinates:")), GBC.std().insets(0, 10, 5, 0)); 81 82 taLatLon = new JTextArea(5, 24); 85 83 taLatLon.getDocument().addDocumentListener(new CoordinateListener()); 86 spScroll = new JScrollPane(taLatLon); 87 pnl.add(spScroll, GBC.eol().insets(0,10,0,0).fill().weight(2.0, 2.0)); 88 89 //Radio button setup 90 bgType = new ButtonGroup(); 91 92 rbNodes = new JRadioButton("Nodes", true); 93 rbNodes.setActionCommand("nodes"); 94 bgType.add(rbNodes); 95 pnl.add(rbNodes); 96 97 rbWay = new JRadioButton("Way"); 98 rbWay.setActionCommand("way"); 99 bgType.add(rbWay); 100 pnl.add(rbWay); 101 102 rbClosedWay = new JRadioButton("Closed Way (Area)"); 103 rbClosedWay.setActionCommand("area"); 104 bgType.add(rbClosedWay); 105 pnl.add(rbClosedWay, GBC.eol()); 106 107 //pnl.add(bgType, GBC.eol().insets(0,10,0,0).fill(GBC.HORIZONTAL).weight(2.0, 0.0)); 108 //pnl.add(new JRadioButton("test")); 109 //pnl.add(bgType); 110 111 pnl.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0,5,0,5)); 84 spScroll = new JScrollPane(taLatLon); 85 pnl.add(spScroll, GBC.eol().insets(0, 10, 0, 0).fill().weight(2.0, 2.0)); 86 87 //Radio button setup 88 bgType = new ButtonGroup(); 89 90 rbNodes = new JRadioButton("Nodes", true); 91 rbNodes.setActionCommand("nodes"); 92 bgType.add(rbNodes); 93 pnl.add(rbNodes); 94 95 rbWay = new JRadioButton("Way"); 96 rbWay.setActionCommand("way"); 97 bgType.add(rbWay); 98 pnl.add(rbWay); 99 100 rbClosedWay = new JRadioButton("Closed Way (Area)"); 101 rbClosedWay.setActionCommand("area"); 102 bgType.add(rbClosedWay); 103 pnl.add(rbClosedWay, GBC.eol()); 104 105 pnl.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0, 5, 0, 5)); 112 106 113 107 pnl.add(new HtmlPanel( 114 tr("Enter the coordinates for the new nodes, one for each line.<br/>If you enter two lines with the same coordinates there will be generated duplicate nodes.<br/>You can separate longitude and latitude with space, comma or semicolon.<br/>" + 115 "Use positive numbers or N, E characters to indicate North or East cardinal direction.<br/>" + 116 "For South and West cardinal directions you can use either negative numbers or S, W characters.<br/>" + 117 "Coordinate value can be in one of three formats:<ul>" + 118 "<li><i>degrees</i><tt>°</tt></li>" + 119 "<li><i>degrees</i><tt>°</tt> <i>minutes</i><tt>'</tt></li>" + 120 "<li><i>degrees</i><tt>°</tt> <i>minutes</i><tt>'</tt> <i>seconds</i><tt>"</tt></li>" + 121 "</ul>" + 122 "Symbols <tt>°</tt>, <tt>'</tt>, <tt>′</tt>, <tt>"</tt>, <tt>″</tt> are optional.<br/><br/>" + 123 "Some examples:<ul>" + 124 "<li>49.29918° 19.24788°</li>" + 125 "<li>N 49.29918 E 19.24788</li>" + 126 "<li>W 49°29.918' S 19°24.788'</li>" + 127 "<li>N 49°29'04" E 19°24'43"</li>" + 128 "<li>49.29918 N, 19.24788 E</li>" + 129 "<li>49°29'21" N 19°24'38" E</li>" + 130 "<li>49 29 51, 19 24 18</li>" + 131 "<li>49 29, 19 24</li>" + 132 "<li>E 49 29, N 19 24</li>" + 133 "<li>49° 29; 19° 24</li>" + 134 "<li>N 49° 29, W 19° 24</li>" + 135 "<li>49° 29.5 S, 19° 24.6 E</li>" + 136 "<li>N 49 29.918 E 19 15.88</li>" + 137 "<li>49 29.4 19 24.5</li>" + 138 "<li>-49 29.4 N -19 24.5 W</li></ul>" + 139 "<li>48 deg 42' 52.13\" N, 21 deg 11' 47.60\" E</li></ul>" 140 )), 108 tr("Enter the coordinates for the new nodes, one for each line.<br/>"+ 109 "If you enter two lines with the same coordinates there will be generated duplicate nodes.<br/>"+ 110 "You can separate longitude and latitude with space, comma or semicolon.<br/>" + 111 "Use positive numbers or N, E characters to indicate North or East cardinal direction.<br/>" + 112 "For South and West cardinal directions you can use either negative numbers or S, W characters.<br/>" + 113 "Coordinate value can be in one of three formats:<ul>" + 114 "<li><i>degrees</i><tt>°</tt></li>" + 115 "<li><i>degrees</i><tt>°</tt> <i>minutes</i><tt>'</tt></li>" + 116 "<li><i>degrees</i><tt>°</tt> <i>minutes</i><tt>'</tt> <i>seconds</i><tt>"</tt></li>" + 117 "</ul>" + 118 "Symbols <tt>°</tt>, <tt>'</tt>, <tt>′</tt>, <tt>"</tt>, <tt>″</tt> are optional.<br/><br/>" + 119 "Some examples:<ul>" + 120 "<li>49.29918° 19.24788°</li>" + 121 "<li>N 49.29918 E 19.24788</li>" + 122 "<li>W 49°29.918' S 19°24.788'</li>" + 123 "<li>N 49°29'04" E 19°24'43"</li>" + 124 "<li>49.29918 N, 19.24788 E</li>" + 125 "<li>49°29'21" N 19°24'38" E</li>" + 126 "<li>49 29 51, 19 24 18</li>" + 127 "<li>49 29, 19 24</li>" + 128 "<li>E 49 29, N 19 24</li>" + 129 "<li>49° 29; 19° 24</li>" + 130 "<li>N 49° 29, W 19° 24</li>" + 131 "<li>49° 29.5 S, 19° 24.6 E</li>" + 132 "<li>N 49 29.918 E 19 15.88</li>" + 133 "<li>49 29.4 19 24.5</li>" + 134 "<li>-49 29.4 N -19 24.5 W</li></ul>" + 135 "<li>48 deg 42' 52.13\" N, 21 deg 11' 47.60\" E</li></ul>" 136 )), 141 137 GBC.eol().fill().weight(1.0, 1.0)); 142 138 … … 160 156 public void stateChanged(ChangeEvent e) { 161 157 switch (tabs.getModel().getSelectedIndex()) { 162 163 158 case 0: parseLatLonUserInput(); break; 159 default: throw new AssertionError(); 164 160 } 165 161 } … … 169 165 170 166 public LatLonDialog(Component parent, String title, String help) { 171 super(Main.parent, tr("Add Node..."), new String[] { 172 setButtonIcons(new String[] { 167 super(Main.parent, tr("Add Node..."), new String[] {tr("Ok"), tr("Cancel")}); 168 setButtonIcons(new String[] {"ok", "cancel"}); 173 169 configureContextsensitiveHelp("/Action/AddNode", true); 174 170 … … 182 178 } 183 179 this.latLonCoordinates = ll; 184 String text = ""; 185 for (LatLon latlon : ll) { 186 text = text + latlon.latToString(CoordinateFormat.getDefaultFormat()) + " " + latlon.lonToString(CoordinateFormat.getDefaultFormat()) + "\n"; 180 String text = ""; 181 for (LatLon latlon : ll) { 182 text = text + latlon.latToString(CoordinateFormat.getDefaultFormat()) 183 + " " + latlon.lonToString(CoordinateFormat.getDefaultFormat()) + "\n"; 187 184 } 188 185 taLatLon.setText(text); … … 224 221 // 225 222 NumberFormat f = NumberFormat.getNumberInstance(); 226 Number n =null;223 Number n = null; 227 224 ParsePosition pp = new ParsePosition(0); 228 n = f.parse(input,pp); 229 if (pp.getErrorIndex() >= 0 || pp.getIndex() <input.length()) {225 n = f.parse(input, pp); 226 if (pp.getErrorIndex() >= 0 || pp.getIndex() < input.length()) { 230 227 // fall back - try to parse with the english locale 231 228 // … … 233 230 f = NumberFormat.getNumberInstance(Locale.ENGLISH); 234 231 n = f.parse(input, pp); 235 if (pp.getErrorIndex() >= 0 || pp.getIndex() <input.length())232 if (pp.getErrorIndex() >= 0 || pp.getIndex() < input.length()) 236 233 return null; 237 234 } 238 return n== null ? null : n.doubleValue(); 235 return n == null ? null : n.doubleValue(); 239 236 } 240 237 … … 243 240 try { 244 241 latLons = parseLatLons(taLatLon.getText()); 245 Boolean working = true; 246 int i=0;247 while (working && i < latLons.length) { 248 if (!LatLon.isValidLat(latLons[i].lat()) || !LatLon.isValidLon(latLons[i].lon())) { 242 Boolean working = true; 243 int i = 0; 244 while (working && i < latLons.length) { 245 if (!LatLon.isValidLat(latLons[i].lat()) || !LatLon.isValidLon(latLons[i].lon())) { 249 246 latLons = null; 250 working = false; 247 working = false; 251 248 } 252 i++; 253 } 249 i++; 250 } 254 251 } catch (IllegalArgumentException e) { 255 252 latLons = null; … … 260 257 setOkEnabled(false); 261 258 } else { 262 clearErrorFeedback(taLatLon,tr("Please enter a GPS coordinates")); 259 clearErrorFeedback(taLatLon, tr("Please enter a GPS coordinates")); 263 260 latLonCoordinates = latLons; 264 261 setOkEnabled(true); … … 279 276 preferenceKey, 280 277 WindowGeometry.centerInWindow(getParent(), getSize()) 281 ).applySafe(this); 278 ).applySafe(this); 282 279 } else { 283 280 new WindowGeometry(this).remember(preferenceKey); … … 301 298 302 299 static class TextFieldFocusHandler implements FocusListener { 303 @Override 300 @Override 304 301 public void focusGained(FocusEvent e) { 305 302 Component c = e.getComponent(); 306 303 if (c instanceof JTextArea) { 307 JTextArea tf = (JTextArea)c; 304 JTextArea tf = (JTextArea) c; 308 305 tf.selectAll(); 309 306 } 310 307 } 311 @Override 308 309 @Override 312 310 public void focusLost(FocusEvent e) {} 313 311 } 314 312 315 313 private static LatLon[] parseLatLons(final String text) { 316 String lines[]= text.split("\\r?\\n");314 String[] lines = text.split("\\r?\\n"); 317 315 List<LatLon> latLons = new ArrayList<>(); 318 316 for (String line : lines) { … … 426 424 } 427 425 428 private static void setLatLon(final LatLonHolder latLon, final double coordDeg, final double coordMin, final double coordSec, final String card) { 426 private static void setLatLon(final LatLonHolder latLon, final double coordDeg, final double coordMin, final double coordSec, 427 final String card) { 429 428 if (coordDeg < -180 || coordDeg > 180 || coordMin < 0 || coordMin >= 60 || coordSec < 0 || coordSec > 60) { 430 429 throw new IllegalArgumentException("out of range"); … … 452 451 //not fired 453 452 } 453 454 454 @Override public void insertUpdate(DocumentEvent e) { 455 455 updateButtons(); 456 456 } 457 457 458 @Override public void removeUpdate(DocumentEvent e) { 458 459 updateButtons(); 459 460 } 461 460 462 private void updateButtons() { 461 463 String text = taLatLon.getText(); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTagAction.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.multitagger; 2 3 … … 20 21 */ 21 22 public MultiTagAction() { 22 super(tr("Tag multiple objects [alpha]"), (String)null, tr("Edit tags of object list in table"), 23 super(tr("Tag multiple objects [alpha]"), (String) null, tr("Edit tags of object list in table"), 23 24 Shortcut.registerShortcut("multitag", tr("Edit: {0}", tr("Tag multiple objects")), KeyEvent.VK_T, Shortcut.CTRL), 24 25 true, "multitag", true); … … 37 38 @Override 38 39 protected void updateEnabledState() { 39 setEnabled(getLayerManager().getEditLayer() !=null);40 setEnabled(getLayerManager().getEditLayer() != null); 40 41 } 41 42 42 43 @Override 43 44 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 44 setEnabled(getLayerManager().getEditLayer() !=null);45 if (dlg !=null && dlg.isVisible()) {45 setEnabled(getLayerManager().getEditLayer() != null); 46 if (dlg != null && dlg.isVisible()) { 46 47 dlg.selectionChanged(selection); 47 48 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTagDialog.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.multitagger; 2 3 … … 71 72 72 73 private static final String HISTORY_KEY = "utilsplugin2.multitaghistory"; 73 String defaultHistory []= {"addr:street, addr:housenumber, building, ${area}",74 "highway, name, ${id}, ${length}", 75 74 String[] defaultHistory = {"addr:street, addr:housenumber, building, ${area}", 75 "highway, name, ${id}, ${length}", 76 "name name:en name:ru name:de"}; 76 77 77 78 public MultiTagDialog() { 78 super(Main.parent, 79 super(Main.parent, tr("Edit tags"), new String[]{tr("Ok"), tr("Cancel")}, false); 79 80 JPanel pnl = new JPanel(new GridBagLayout()); 80 81 tbl = createTable(); … … 82 83 cbTagSet.addItemListener(tagSetChanger); 83 84 cbTagSet.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) 84 85 .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), "applyTagSet"); 85 86 cbTagSet.getActionMap().put("applyTagSet", tagSetChanger); 86 87 87 88 tbl.addMouseListener(new PopupMenuLauncher(createPopupMenu())); 88 89 89 pnl.add(cbTagSet,GBC.std().fill(GBC.HORIZONTAL)); 90 pnl.add(new JButton(new DeleteFromHistoryAction()),GBC.std()); 91 pnl.add(new JButton(new FindMatchingAction()),GBC.std()); 90 pnl.add(cbTagSet, GBC.std().fill(GBC.HORIZONTAL)); 91 pnl.add(new JButton(new DeleteFromHistoryAction()), GBC.std()); 92 pnl.add(new JButton(new FindMatchingAction()), GBC.std()); 92 93 final JToggleButton jt = new JToggleButton("", ImageProvider.get("restart"), true); 93 94 jt.setToolTipText(tr("Sync with JOSM selection")); 94 jt.addActionListener(new ActionListener(){ 95 jt.addActionListener(new ActionListener() { 95 96 @Override public void actionPerformed(ActionEvent e) { 96 97 tableModel.setWatchSelection(jt.isSelected()); 97 }; 98 }); 99 pnl.add(jt,GBC.eol()); 100 98 } 99 }); 100 pnl.add(jt, GBC.eol()); 101 101 102 102 pnl.add(createTypeFilterPanel(), GBC.eol().fill(GBC.HORIZONTAL)); 103 pnl.add(tbl.getTableHeader(),GBC.eop().fill(GBC.HORIZONTAL)); 103 pnl.add(tbl.getTableHeader(), GBC.eop().fill(GBC.HORIZONTAL)); 104 104 105 105 pnl.add(new JScrollPane(tbl), GBC.eol().fill(GBC.BOTH)); … … 132 132 for (final OsmPrimitiveType type: OsmPrimitiveType.values()) { 133 133 final JToggleButton jt = new JToggleButton("", ImageProvider.get(type), true); 134 jt.addActionListener(new ActionListener(){ 134 jt.addActionListener(new ActionListener() { 135 135 @Override 136 136 public void actionPerformed(ActionEvent e) { … … 169 169 /*private OsmPrimitive getSelectedPrimitive() { 170 170 int idx = tbl.getSelectedRow(); 171 if (idx>=0) { 171 if (idx>= 0) { 172 172 return tableModel.getPrimitiveAt(tbl.convertRowIndexToModel(idx)); 173 173 } else { … … 176 176 }*/ 177 177 178 private final MouseAdapter tableMouseAdapter = new MouseAdapter() { 178 private final MouseAdapter tableMouseAdapter = new MouseAdapter() { 179 179 @Override 180 180 public void mouseClicked(MouseEvent e) { 181 if (e.getClickCount() >1 && Main.isDisplayingMapView()) {181 if (e.getClickCount() > 1 && Main.isDisplayingMapView()) { 182 182 AutoScaleAction.zoomTo(currentSelection); 183 183 } … … 189 189 public void valueChanged(ListSelectionEvent e) { 190 190 currentSelection = getSelectedPrimitives(); 191 if (currentSelection != null && Main.isDisplayingMapView() 191 if (currentSelection != null && Main.isDisplayingMapView()) { 192 192 if (highlightHelper.highlightOnly(currentSelection)) { 193 193 Main.map.mapView.repaint(); … … 210 210 OsmDataLayer l = Main.getLayerManager().getEditLayer(); 211 211 AutoCompletionManager autocomplete = l.data.getAutoCompletionManager(); 212 for (int i =0; i<tableModel.mainTags.length; i++) {213 214 215 216 217 218 212 for (int i = 0; i < tableModel.mainTags.length; i++) { 213 if (tableModel.isSpecialTag[i]) continue; 214 AutoCompletingTextField tf = new AutoCompletingTextField(0, false); 215 AutoCompletionList acList = new AutoCompletionList(); 216 autocomplete.populateWithTagValues(acList, tableModel.mainTags[i]); 217 tf.setAutoCompletionList(acList); 218 tbl.getColumnModel().getColumn(i+1).setCellEditor(tf); 219 219 } 220 220 } … … 236 236 } 237 237 }); 238 menu.add(new AbstractAction(tr("Remove tag"), ImageProvider.get("dialogs", "delete")){ 238 menu.add(new AbstractAction(tr("Remove tag"), ImageProvider.get("dialogs", "delete")) { 239 239 @Override 240 240 public void actionPerformed(ActionEvent e) { … … 249 249 } 250 250 }); 251 menu.add(new AbstractAction(tr("Duplicate tags from the first"), ImageProvider.get("copy")){ 251 menu.add(new AbstractAction(tr("Duplicate tags from the first"), ImageProvider.get("copy")) { 252 252 @Override 253 253 public void actionPerformed(ActionEvent e) { 254 254 tableModel.setAutoCommit(false); 255 255 for (int c: tbl.getSelectedColumns()) { 256 if (c ==0 || tableModel.isSpecialTag[c-1]) continue;256 if (c == 0 || tableModel.isSpecialTag[c-1]) continue; 257 257 boolean first = true; 258 258 String value = ""; … … 261 261 value = (String) tableModel.getValueAt(tbl.convertRowIndexToModel(r), tbl.convertColumnIndexToModel(c)); 262 262 } 263 first =false;263 first = false; 264 264 tableModel.setValueAt(value, tbl.convertRowIndexToModel(r), tbl.convertColumnIndexToModel(c)); 265 265 } … … 285 285 286 286 private class DeleteFromHistoryAction extends AbstractAction { 287 publicDeleteFromHistoryAction() {288 super("", ImageProvider.get("dialogs","delete")); 287 DeleteFromHistoryAction() { 288 super("", ImageProvider.get("dialogs", "delete")); 289 289 putValue(SHORT_DESCRIPTION, tr("Delete from history")); 290 290 } … … 305 305 306 306 private class FindMatchingAction extends AbstractAction { 307 publicFindMatchingAction() {308 super("", ImageProvider.get("dialogs","search")); 307 FindMatchingAction() { 308 super("", ImageProvider.get("dialogs", "search")); 309 309 putValue(SHORT_DESCRIPTION, tr("Find primitives with these tags")); 310 310 } … … 322 322 public void itemStateChanged(ItemEvent e) { 323 323 // skip text-changing enevts, we need only combobox-selecting ones 324 if (cbTagSet.getSelectedIndex() <0) return;324 if (cbTagSet.getSelectedIndex() < 0) return; 325 325 actionPerformed(null); 326 326 } … … 329 329 public void actionPerformed(ActionEvent e) { 330 330 String s = cbTagSet.getText(); 331 if (s ==null || s.isEmpty() || s.equals(oldTags)) return;331 if (s == null || s.isEmpty() || s.equals(oldTags)) return; 332 332 oldTags = s; 333 333 cbTagSet.addCurrentItemToHistory(); … … 335 335 specifyTagSet(s); 336 336 } 337 338 }; 337 } 339 338 340 339 private void specifyTagSet(String s) { … … 346 345 347 346 tbl.getColumnModel().getColumn(0).setMaxWidth(20); 348 for (int i =1; i<tableModel.getColumnCount(); i++) {347 for (int i = 1; i < tableModel.getColumnCount(); i++) { 349 348 TableHelper.adjustColumnWidth(tbl, i, 100); 350 349 } … … 355 354 class ColoredRenderer extends DefaultTableCellRenderer { 356 355 private final Color highlightColor = 357 Main.pref.getColor( 358 new Color(255, 255,200));356 Main.pref.getColor(marktr("Multitag Background: highlight"), 357 new Color(255, 255, 200)); 359 358 @Override 360 359 public Component getTableCellRendererComponent(JTable table, Object value, boolean … … 362 361 int row1 = tbl.convertRowIndexToModel(row); 363 362 JLabel label = (JLabel) super.getTableCellRendererComponent( 364 table, value, isSelected, hasFocus, row, column); 363 table, value, isSelected, hasFocus, row, column); 365 364 if (tbl.isRowSelected(row1) && !tbl.isColumnSelected(column)) { 366 365 label.setBackground(highlightColor); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTaggerTableModel.java
r32333 r32410 1 // License: GPL. Copyright 2013 by Alexei Kasatkin 2 1 // License: GPL. For details, see LICENSE file. 3 2 package org.openstreetmap.josm.plugins.utilsplugin2.multitagger; 4 5 3 6 4 import java.util.ArrayList; … … 24 22 import org.openstreetmap.josm.tools.Geometry; 25 23 26 /**27 *28 */29 24 public class MultiTaggerTableModel extends AbstractTableModel implements SelectionChangedListener { 30 25 31 26 ArrayList<OsmPrimitive> list = new ArrayList<>(50); 32 String mainTags []= new String[]{};33 boolean isSpecialTag []= new boolean[]{};27 String[] mainTags = new String[]{}; 28 boolean[] isSpecialTag = new boolean[]{}; 34 29 Set<OsmPrimitiveType> shownTypes = new HashSet<>(); 35 30 private boolean autoCommit = true; … … 41 36 Collections.addAll(shownTypes, OsmPrimitiveType.values()); 42 37 } 43 38 44 39 @Override 45 40 public int getRowCount() { … … 54 49 public void setWatchSelection(boolean watchSelection) { 55 50 this.watchSelection = watchSelection; 56 if (watchSelection && Main.getLayerManager().getEditLayer() != null) 51 if (watchSelection && Main.getLayerManager().getEditLayer() != null) 57 52 selectionChanged(Main.getLayerManager().getEditDataSet().getSelected()); 58 53 } … … 60 55 @Override 61 56 public Object getValueAt(int rowIndex, int columnIndex) { 62 if (columnIndex ==0) {57 if (columnIndex == 0) { 63 58 return list.get(rowIndex).getDisplayType(); 64 59 } … … 71 66 return String.valueOf(p.getUniqueId()); 72 67 } else if (var.equals("type")) { 73 return OsmPrimitiveType.from(p).getAPIName().substring(0,1).toUpperCase(); 68 return OsmPrimitiveType.from(p).getAPIName().substring(0, 1).toUpperCase(); 74 69 } else if (var.equals("area")) { 75 70 if (p.getDisplayType() == OsmPrimitiveType.CLOSEDWAY) { … … 82 77 return String.format("%.1f", ((Way) p).getLength()); 83 78 } 84 } 79 } 85 80 return ""; 86 81 } … … 88 83 @Override 89 84 public Class<?> getColumnClass(int columnIndex) { 90 if (columnIndex ==0) {85 if (columnIndex == 0) { 91 86 return OsmPrimitiveType.class; 92 87 } else { … … 94 89 } 95 90 } 96 91 97 92 @Override 98 93 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { … … 103 98 @Override 104 99 public boolean isCellEditable(int rowIndex, int columnIndex) { 105 if (columnIndex ==0) return false;100 if (columnIndex == 0) return false; 106 101 return !isSpecialTag[columnIndex-1]; 107 102 } … … 109 104 @Override 110 105 public void setValueAt(Object value, int rowIndex, int columnIndex) { 111 if (columnIndex ==0 || isSpecialTag[columnIndex-1]) return;106 if (columnIndex == 0 || isSpecialTag[columnIndex-1]) return; 112 107 if (columnIndex >= getColumnCount() || rowIndex >= getRowCount()) return; 113 if (value ==null) value="";108 if (value == null) value = ""; 114 109 String val = ((String) value).trim(); 115 110 OsmPrimitive sel = list.get(rowIndex); 116 111 String key = mainTags[columnIndex-1]; 117 112 String newValue = sel.get(key); 118 if (newValue == null) newValue ="";113 if (newValue == null) newValue = ""; 119 114 if (!val.equals(newValue)) { 120 115 Command cmd = new ChangePropertyCommand(sel, key, (String) value); … … 124 119 cmds.add(cmd); 125 120 } 126 127 121 } 128 122 } 129 130 123 131 124 @Override 132 125 public String getColumnName(int column) { 133 if (column ==0) return "";126 if (column == 0) return ""; 134 127 return mainTags[column-1]; 135 128 } 136 129 137 130 public OsmPrimitive getPrimitiveAt(int number) { 138 if (number <0 || number>=list.size()) {131 if (number < 0 || number >= list.size()) { 139 132 return null; 140 133 } else { … … 142 135 } 143 136 } 144 137 145 138 public void setupColumnsFromText(String txt) { 146 139 String[] tags = txt.trim().split("[\\s,]+"); 147 140 mainTags = new String[tags.length]; 148 141 isSpecialTag = new boolean[tags.length]; 149 int i =0;142 int i = 0; 150 143 for (String t: tags) { 151 144 if (t.startsWith("${") && t.endsWith("}")) { … … 163 156 StringBuilder sb = new StringBuilder(); 164 157 boolean notFirst = false; 165 for (int i =0; i<mainTags.length; i++) {158 for (int i = 0; i < mainTags.length; i++) { 166 159 if (!isSpecialTag[i]) { 167 168 169 170 171 160 if (notFirst) sb.append(" | "); 161 sb.append("\""); 162 sb.append(mainTags[i]); 163 sb.append("\":"); 164 notFirst = true; 172 165 } 173 } ;166 } 174 167 return sb.toString(); 175 168 } 176 169 177 170 void updateData(Collection<? extends OsmPrimitive> sel) { 178 if (table.isEditing()) table.getCellEditor().stopCellEditing(); 179 180 list.clear(); 171 if (table.isEditing()) table.getCellEditor().stopCellEditing(); 172 173 list.clear(); 181 174 for (OsmPrimitive p : sel) { 182 175 if (shownTypes.contains(p.getDisplayType())) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryAction.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 2 5 3 6 import java.awt.event.ActionEvent; … … 6 9 import java.util.Collection; 7 10 import java.util.List; 11 8 12 import javax.swing.JOptionPane; 13 9 14 import org.openstreetmap.josm.Main; 10 15 import org.openstreetmap.josm.actions.JosmAction; 11 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 17 import org.openstreetmap.josm.gui.Notification; 13 import static org.openstreetmap.josm.tools.I18n.tr;14 18 import org.openstreetmap.josm.tools.Shortcut; 15 19 … … 24 28 public ReplaceGeometryAction() { 25 29 super(TITLE, "dumbutils/replacegeometry", tr("Replace geometry of selected object with a new one"), 26 Shortcut.registerShortcut("tools:replacegeometry", tr("Tool: {0}", tr("Replace Geometry")), KeyEvent.VK_G, Shortcut.CTRL_SHIFT) 27 ,true);30 Shortcut.registerShortcut("tools:replacegeometry", tr("Tool: {0}", tr("Replace Geometry")), KeyEvent.VK_G, Shortcut.CTRL_SHIFT), 31 true); 28 32 } 29 33 … … 39 43 new Notification( 40 44 tr("This tool replaces geometry of one object with another, and so requires exactly two objects to be selected.") 41 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 45 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 42 46 return; 43 47 } … … 45 49 OsmPrimitive firstObject = selection.get(0); 46 50 OsmPrimitive secondObject = selection.get(1); 47 51 48 52 try { 49 53 ReplaceGeometryCommand replaceCommand = 50 54 ReplaceGeometryUtils.buildReplaceWithNewCommand(firstObject, secondObject); 51 55 52 56 // action was canceled 53 57 if (replaceCommand == null) 54 58 return; 55 59 56 60 Main.main.undoRedo.add(replaceCommand); 57 61 } catch (IllegalArgumentException ex) { 58 62 new Notification( 59 ex.getMessage() 60 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 63 ex.getMessage() 64 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 61 65 } catch (ReplaceGeometryException ex) { 62 66 new Notification( 63 ex.getMessage() 64 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 67 ex.getMessage() 68 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 65 69 } 66 70 } … … 72 76 73 77 @Override 74 protected void updateEnabledState( 75 setEnabled(selection != null && selection.size() >= 2 78 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 79 setEnabled(selection != null && selection.size() >= 2); 76 80 } 77 81 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryCommand.java
r28335 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry; 2 3 3 4 import java.util.Collection; 5 4 6 import javax.swing.Icon; 7 5 8 import org.openstreetmap.josm.command.Command; 6 9 import org.openstreetmap.josm.command.SequenceCommand; … … 9 12 /** 10 13 * Command to replace the geometry of one object with another. 11 * 14 * 12 15 * @author joshdoe 13 16 */ 14 17 public class ReplaceGeometryCommand extends SequenceCommand { 15 18 private final String description; 16 19 17 20 public ReplaceGeometryCommand(String description, Collection<Command> sequence) { 18 21 super(description, sequence); … … 24 27 return description; 25 28 } 26 29 27 30 @Override 28 31 public Icon getDescriptionIcon() { 29 32 return ImageProvider.get("dumbutils", "replacegeometry"); 30 33 } 31 34 32 35 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryException.java
r28335 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry; 2 3 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry; 2 3 … … 43 44 */ 44 45 public final class ReplaceGeometryUtils { 46 47 private ReplaceGeometryUtils() { 48 // Hide default constructor for utilities classes 49 } 50 45 51 /** 46 52 * Replace new or uploaded object with new object 47 *48 * @param firstObject49 * @param secondObject50 * @return51 53 */ 52 54 public static ReplaceGeometryCommand buildReplaceWithNewCommand(OsmPrimitive firstObject, OsmPrimitive secondObject) { … … 60 62 return buildUpgradeNodeCommand((Node) secondObject, firstObject); 61 63 } else { 62 throw new IllegalArgumentException(tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way.")); 63 } 64 } 65 64 throw new IllegalArgumentException( 65 tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way.")); 66 } 67 } 68 66 69 /** 67 70 * Replace subjectObject geometry with referenceObject geometry and merge tags 68 71 * and relation memberships. 69 *70 * @param subjectObject71 * @param referenceSubject72 * @return73 72 */ 74 73 public static ReplaceGeometryCommand buildReplaceCommand(OsmPrimitive subjectObject, OsmPrimitive referenceSubject) { … … 83 82 return buildUpgradeNodeCommand((Node) referenceSubject, subjectObject); 84 83 } else { 85 throw new IllegalArgumentException(tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way.")); 84 throw new IllegalArgumentException( 85 tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way.")); 86 86 } 87 87 } … … 89 89 /** 90 90 * Replace a new or uploaded node with a new node 91 * @param firstNode92 * @param secondNode93 * @return94 91 */ 95 92 public static ReplaceGeometryCommand buildReplaceNodeWithNewCommand(Node firstNode, Node secondNode) { … … 103 100 return buildReplaceNodeCommand(firstNode, secondNode); 104 101 } 105 102 106 103 /** 107 104 * Replace a node with another node (similar to MergeNodesAction) 108 *109 * @param subjectNode110 * @param referenceNode111 * @return112 105 */ 113 106 public static ReplaceGeometryCommand buildReplaceNodeCommand(Node subjectNode, Node referenceNode) { … … 128 121 commands); 129 122 } 130 123 131 124 /** 132 125 * Upgrade a node to a way or multipolygon … … 167 160 168 161 List<Command> commands = new ArrayList<>(); 169 AbstractMap<String, String> nodeTags = (AbstractMap<String, String>)subjectNode.getKeys();162 AbstractMap<String, String> nodeTags = subjectNode.getKeys(); 170 163 171 164 // merge tags … … 210 203 commands); 211 204 } 212 205 213 206 public static ReplaceGeometryCommand buildReplaceWayWithNewCommand(List<Way> selection) { 214 207 // determine which way will be replaced and which will provide the geometry 215 208 boolean overrideNewCheck = false; 216 209 int idxNew = selection.get(0).isNew() ? 0 : 1; 217 if (selection.get(1-idxNew).isNew()210 if (selection.get(1-idxNew).isNew()) { 218 211 // if both are new, select the one with all the DB nodes 219 212 boolean areNewNodes = false; … … 233 226 Way referenceWay = selection.get(idxNew); 234 227 Way subjectWay = selection.get(1 - idxNew); 235 236 if (!overrideNewCheck && (subjectWay.isNew() || !referenceWay.isNew())228 229 if (!overrideNewCheck && (subjectWay.isNew() || !referenceWay.isNew())) { 237 230 throw new ReplaceGeometryException( 238 231 tr("Please select one way that exists in the database and one new way with correct geometry.")); … … 240 233 return buildReplaceWayCommand(subjectWay, referenceWay); 241 234 } 242 235 243 236 public static ReplaceGeometryCommand buildReplaceWayCommand(Way subjectWay, Way referenceWay) { 244 237 … … 247 240 throw new ReplaceGeometryException(tr("The ways must be entirely within the downloaded area.")); 248 241 } 249 242 250 243 if (hasImportantNode(referenceWay, subjectWay)) { 251 244 throw new ReplaceGeometryException( … … 254 247 255 248 List<Command> commands = new ArrayList<>(); 256 249 257 250 // merge tags 258 251 try { … … 263 256 return null; 264 257 } 265 258 266 259 // Prepare a list of nodes that are not used anywhere except in the way 267 260 List<Node> nodePool = getUnimportantNodes(subjectWay); … … 269 262 // And the same for geometry, list nodes that can be freely deleted 270 263 List<Node> geometryPool = new LinkedList<>(); 271 for (Node node : referenceWay.getNodes()264 for (Node node : referenceWay.getNodes()) { 272 265 List<OsmPrimitive> referrers = node.getReferrers(); 273 if (node.isNew() && !node.isDeleted() && referrers.size() == 1266 if (node.isNew() && !node.isDeleted() && referrers.size() == 1 274 267 && referrers.get(0).equals(referenceWay) && !subjectWay.containsNode(node) 275 268 && !hasInterestingKey(node) && !geometryPool.contains(node)) … … 278 271 279 272 boolean useRobust = Main.pref.getBoolean("utilsplugin2.replace-geometry.robustAssignment", true); 280 273 281 274 // Find new nodes that are closest to the old ones, remove matching old ones from the pool 282 275 // Assign node moves with least overall distance moved … … 287 280 int nLen = nodePool.size(); 288 281 int N = Math.max(gLen, nLen); 289 double cost[][]= new double[N][N];282 double[][] cost = new double[N][N]; 290 283 for (int i = 0; i < N; i++) { 291 284 for (int j = 0; j < N; j++) { … … 319 312 nodePool.remove(n); 320 313 } 321 } 322 catch (Exception e) { 314 } catch (Exception e) { 323 315 useRobust = false; 324 316 new Notification( 325 tr("Exceeded iteration limit for robust method, using simpler method.") 326 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 317 tr("Exceeded iteration limit for robust method, using simpler method.") 318 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 327 319 nodeAssoc = new HashMap<>(); 328 320 } … … 341 333 342 334 // Now that we have replacement list, move all unused new nodes to nodePool (and delete them afterwards) 343 for (Node n : geometryPool)344 if (nodeAssoc.containsKey(n)335 for (Node n : geometryPool) { 336 if (nodeAssoc.containsKey(n)) 345 337 nodePool.add(n); 338 } 346 339 347 340 // And prepare a list of nodes with all the replacements 348 341 List<Node> geometryNodes = referenceWay.getNodes(); 349 for (int i = 0; i < geometryNodes.size(); i++)350 if (nodeAssoc.containsKey(geometryNodes.get(i))342 for (int i = 0; i < geometryNodes.size(); i++) { 343 if (nodeAssoc.containsKey(geometryNodes.get(i))) 351 344 geometryNodes.set(i, nodeAssoc.get(geometryNodes.get(i))); 345 } 352 346 353 347 // Now do the replacement … … 355 349 356 350 // Move old nodes to new positions 357 for (Node node : nodeAssoc.keySet())351 for (Node node : nodeAssoc.keySet()) { 358 352 commands.add(new MoveCommand(nodeAssoc.get(node), node.getCoor())); 353 } 359 354 360 355 // Remove geometry way from selection … … 365 360 366 361 // Delete nodes that are not used anymore 367 if (!nodePool.isEmpty()362 if (!nodePool.isEmpty()) 368 363 commands.add(new DeleteCommand(nodePool)); 369 364 … … 376 371 /** 377 372 * Create a list of nodes that are not used anywhere except in the way. 378 *379 * @param way380 * @return381 373 */ 382 374 protected static List<Node> getUnimportantNodes(Way way) { … … 391 383 return nodePool; 392 384 } 393 385 394 386 /** 395 387 * Checks if a way has at least one important node (e.g. interesting tag, 396 388 * role membership), and thus cannot be safely modified. 397 *398 * @param way399 * @return400 389 */ 401 390 protected static boolean hasImportantNode(Way geometry, Way way) { … … 417 406 return false; 418 407 } 419 408 420 409 protected static boolean hasInterestingKey(OsmPrimitive object) { 421 410 for (String key : object.getKeys().keySet()) { … … 434 423 return false; 435 424 } 436 425 437 426 protected static boolean isInArea(Way way, Area area) { 438 427 if (area == null) { … … 448 437 return true; 449 438 } 450 451 439 440 /** 452 441 * Merge tags from source to target object, showing resolution dialog if 453 442 * needed. … … 464 453 TagCollection.unionOfAllPrimitives(primitives), primitives, Collections.singleton(target)); 465 454 } 466 455 467 456 /** 468 457 * Find node from the collection which is nearest to <tt>node</tt>. Max distance is taken in consideration. 469 458 * @return null if there is no such node. 470 459 */ 471 protected static Node findNearestNode( 472 if (nodes.contains(node)460 protected static Node findNearestNode(Node node, Collection<Node> nodes) { 461 if (nodes.contains(node)) 473 462 return node; 474 463 475 464 Node nearest = null; 476 465 // TODO: use meters instead of degrees, but do it fast … … 478 467 LatLon coor = node.getCoor(); 479 468 480 for (Node n : nodes469 for (Node n : nodes) { 481 470 double d = n.getCoor().distance(coor); 482 if (d < distance471 if (d < distance) { 483 472 distance = d; 484 473 nearest = n; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceMembershipAction.java
r32333 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry; 2 3 … … 50 51 secondObject.getDisplayName(DefaultNameFormatter.getInstance()), 51 52 affectedRelations 52 )).setIcon(JOptionPane.INFORMATION_MESSAGE).show(); 53 )).setIcon(JOptionPane.INFORMATION_MESSAGE).show(); 53 54 } else { 54 55 new Notification(tr("The first selected object ''{0}'' is not part of any relation", 55 56 firstObject.getDisplayName(DefaultNameFormatter.getInstance()) 56 )).setIcon(JOptionPane.WARNING_MESSAGE).show(); 57 )).setIcon(JOptionPane.WARNING_MESSAGE).show(); 57 58 } 58 59 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ChildrenMatch.java
r30389 r32410 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.plugins.utilsplugin2.search; 1 3 2 packageorg.openstreetmap.josm.plugins.utilsplugin2.search;4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import org.openstreetmap.josm.actions.search.PushbackTokenizer; … … 7 9 import org.openstreetmap.josm.data.osm.Relation; 8 10 import org.openstreetmap.josm.data.osm.Way; 9 import static org.openstreetmap.josm.tools.I18n.tr;10 11 11 12 /** … … 13 14 */ 14 15 public class ChildrenMatch extends RangeMatch { 15 public ChildrenMatch(PushbackTokenizer.Range range) {super(range);} 16 public ChildrenMatch(PushbackTokenizer.Range range) { 17 super(range); 18 } 19 16 20 public ChildrenMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError { 17 21 this(tokenizer.readRange(tr("Range of child primitives count"))); 18 22 } 19 23 20 @Override 24 @Override 21 25 protected Long getNumber(OsmPrimitive osm) { 22 26 if (osm instanceof Way) { 23 return (long) ((Way)osm).getNodesCount(); 27 return (long) ((Way) osm).getNodesCount(); 24 28 } else if (osm instanceof Relation) { 25 return (long) ((Relation)osm).getMembersCount(); 29 return (long) ((Relation) osm).getMembersCount(); 26 30 } else { 27 31 return null; … … 29 33 } 30 34 31 @Override 35 @Override 32 36 protected String getString() { 33 37 return "children"; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ConnectedMatch.java
r32333 r32410 1 // License: GPL v2 or later. See LICENSE filefor details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.search; 3 3 … … 5 5 import java.util.HashSet; 6 6 import java.util.Set; 7 7 8 import org.openstreetmap.josm.Main; 8 9 import org.openstreetmap.josm.actions.search.SearchCompiler; … … 11 12 import org.openstreetmap.josm.data.osm.Way; 12 13 import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils; 13 14 14 15 15 /** … … 62 62 } 63 63 if (osm instanceof Way) { 64 return connected.contains( (Way)osm);64 return connected.contains(osm); 65 65 } 66 66 return false; 67 67 } 68 68 69 69 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/InsideMatch.java
r32333 r32410 1 /* 2 * To change this license header, choose License Headers in Project Properties. 3 * To change this template file, choose Tools | Templates 4 * and open the template in the editor. 5 */ 6 1 // License: GPL. For details, see LICENSE file. 7 2 package org.openstreetmap.josm.plugins.utilsplugin2.search; 8 3 9 4 import java.util.Collection; 10 5 import java.util.HashSet; 6 11 7 import org.openstreetmap.josm.Main; 12 8 import org.openstreetmap.josm.actions.search.SearchCompiler; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/IntersectingMatch.java
r32333 r32410 1 // License: GPL v2 or later. See LICENSE filefor details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.search; 3 3 … … 5 5 import java.util.HashSet; 6 6 import java.util.Set; 7 7 8 import org.openstreetmap.josm.Main; 8 9 import org.openstreetmap.josm.actions.search.SearchCompiler; … … 12 13 13 14 /** 14 * Find (all) ways intersecting ways or nodes which match the expression. 15 */ 15 * Find (all) ways intersecting ways or nodes which match the expression. 16 */ 16 17 public class IntersectingMatch extends SearchCompiler.UnaryMatch { 17 18 private Collection<Way> intersecting = null; … … 51 52 } 52 53 if (osm instanceof Way) { 53 return intersecting.contains( (Way)osm);54 return intersecting.contains(osm); 54 55 } 55 56 return false; 56 57 } 57 58 58 59 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ParentsMatch.java
r30389 r32410 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.plugins.utilsplugin2.search; 1 3 2 packageorg.openstreetmap.josm.plugins.utilsplugin2.search;4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import org.openstreetmap.josm.actions.search.PushbackTokenizer; 5 7 import org.openstreetmap.josm.actions.search.SearchCompiler; 6 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 import static org.openstreetmap.josm.tools.I18n.tr;8 9 9 10 /** … … 11 12 */ 12 13 public class ParentsMatch extends RangeMatch { 13 public ParentsMatch(PushbackTokenizer.Range range) {super(range);} 14 public ParentsMatch(PushbackTokenizer.Range range) { 15 super(range); 16 } 17 14 18 public ParentsMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError { 15 19 this(tokenizer.readRange(tr("Range of parent primitives count"))); 16 20 } 17 @Override 21 22 @Override 18 23 protected Long getNumber(OsmPrimitive osm) { 19 24 return new Long(osm.getReferrers().size()); 20 25 } 21 @Override 26 27 @Override 22 28 protected String getString() { 23 29 return "parents"; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/RangeMatch.java
r30384 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.search; 2 3 … … 10 11 public abstract class RangeMatch extends SearchCompiler.Match { 11 12 12 13 13 private final long min; 14 private final long max; 14 15 15 public RangeMatch(long min, long max) { 16 this.min = Math.min(min, max); 17 this.max = Math.max(min, max); 18 } 19 20 public RangeMatch(PushbackTokenizer.Range range) { 21 this(range.getStart(), range.getEnd()); 22 } 23 24 protected abstract Long getNumber(OsmPrimitive osm); 25 26 protected abstract String getString(); 27 28 @Override 29 public boolean match(OsmPrimitive osm) { 30 Long num = getNumber(osm); 31 if (num == null) 32 return false; 33 else 34 return (num >= min) && (num <= max); 35 } 36 37 @Override 38 public String toString() { 39 return getString() + "=" + min + "-" + max; 40 } 16 public RangeMatch(long min, long max) { 17 this.min = Math.min(min, max); 18 this.max = Math.max(min, max); 41 19 } 42 20 21 public RangeMatch(PushbackTokenizer.Range range) { 22 this(range.getStart(), range.getEnd()); 23 } 24 25 protected abstract Long getNumber(OsmPrimitive osm); 26 27 protected abstract String getString(); 28 29 @Override 30 public boolean match(OsmPrimitive osm) { 31 Long num = getNumber(osm); 32 if (num == null) 33 return false; 34 else 35 return (num >= min) && (num <= max); 36 } 37 38 @Override 39 public String toString() { 40 return getString() + "=" + min + "-" + max; 41 } 42 } 43 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UsedInRelationsMatch.java
r30389 r32410 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.plugins.utilsplugin2.search; 1 3 2 packageorg.openstreetmap.josm.plugins.utilsplugin2.search;4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import org.openstreetmap.josm.actions.search.PushbackTokenizer; … … 10 12 import org.openstreetmap.josm.data.osm.Way; 11 13 import org.openstreetmap.josm.data.osm.visitor.Visitor; 12 import static org.openstreetmap.josm.tools.I18n.tr;13 14 14 15 /** … … 16 17 */ 17 18 public class UsedInRelationsMatch extends RangeMatch { 18 public UsedInRelationsMatch(PushbackTokenizer.Range range) {super(range);} 19 public UsedInRelationsMatch(PushbackTokenizer.Range range) { 20 super(range); 21 } 22 19 23 public UsedInRelationsMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError { 20 24 this(tokenizer.readRange(tr("Range of referencing relation count"))); 21 25 } 26 22 27 private class RelationCounter implements Visitor { 23 28 int count; 24 29 @Override 25 public void visit(Way w) { } 26 @Override public void visit(Node n) { } 27 @Override public void visit(Relation r) { count++; } 28 @Override public void visit(Changeset cs) { } 30 public void visit(Way w) { 31 // Do nothing 32 } 33 34 @Override 35 public void visit(Node n) { 36 // Do nothing 37 } 38 39 @Override 40 public void visit(Relation r) { 41 count++; 42 } 43 44 @Override 45 public void visit(Changeset cs) { 46 // Do nothing 47 } 29 48 } 49 30 50 RelationCounter counter = new RelationCounter(); 31 51 32 @Override 52 @Override 33 53 protected Long getNumber(OsmPrimitive osm) { 34 counter.count =0;54 counter.count = 0; 35 55 osm.visitReferrers(counter); 36 56 return new Long(counter.count); 37 57 } 38 @Override 58 59 @Override 39 60 protected String getString() { 40 61 return "usedinrelations"; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UsedInWaysMatch.java
r30389 r32410 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.plugins.utilsplugin2.search; 1 3 2 packageorg.openstreetmap.josm.plugins.utilsplugin2.search;4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import org.openstreetmap.josm.actions.search.PushbackTokenizer; … … 10 12 import org.openstreetmap.josm.data.osm.Way; 11 13 import org.openstreetmap.josm.data.osm.visitor.Visitor; 12 import static org.openstreetmap.josm.tools.I18n.tr;13 14 14 15 /** … … 16 17 */ 17 18 public class UsedInWaysMatch extends RangeMatch { 18 public UsedInWaysMatch(PushbackTokenizer.Range range) {super(range);} 19 public UsedInWaysMatch(PushbackTokenizer.Range range) { 20 super(range); 21 } 22 19 23 public UsedInWaysMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError { 20 24 this(tokenizer.readRange(tr("Range of attached ways count"))); 21 25 } 26 22 27 private class WayCounter implements Visitor { 23 28 int count; 24 29 @Override 25 public void visit(Way w) { count++; } 26 @Override public void visit(Node n) { } 27 @Override public void visit(Relation r) { } 28 @Override public void visit(Changeset cs) { } 30 public void visit(Way w) { 31 count++; 32 } 33 34 @Override 35 public void visit(Node n) { 36 // Do nothing 37 } 38 39 @Override 40 public void visit(Relation r) { 41 // Do nothing 42 } 43 44 @Override 45 public void visit(Changeset cs) { 46 // Do nothing 47 } 29 48 } 49 30 50 WayCounter counter = new WayCounter(); 31 51 32 @Override protected Long getNumber(OsmPrimitive osm) { 52 @Override protected Long getNumber(OsmPrimitive osm) { 33 53 if (osm instanceof Node) { 34 counter.count =0;54 counter.count = 0; 35 55 osm.visitReferrers(counter); 36 56 return new Long(counter.count); 37 57 } else return null; 38 58 } 59 39 60 @Override protected String getString() { 40 61 return "wayrefs"; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UtilsSimpleMatchFactory.java
r30389 r32410 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.utilsplugin2.search; 2 3 3 4 import java.util.Arrays; 4 5 import java.util.Collection; 6 5 7 import org.openstreetmap.josm.actions.search.PushbackTokenizer; 6 8 import org.openstreetmap.josm.actions.search.SearchCompiler; … … 8 10 9 11 public class UtilsSimpleMatchFactory implements SimpleMatchFactory { 10 12 11 13 private static Collection<String> keywords = Arrays.asList("usedinways", "usedinrelations", "parents", "children"); 12 14 … … 20 22 if ("usedinways".equals(keyword)) { 21 23 return new UsedInWaysMatch(tokenizer); 22 } else23 if ("usedinrelations".equals(keyword)) {24 return new UsedInRelationsMatch(tokenizer);25 } else26 if ("parents".equals(keyword)) {27 return new ParentsMatch(tokenizer);28 24 } else 29 if ("children".equals(keyword)) { 30 return new ChildrenMatch(tokenizer); 31 } else 32 return null; 33 }; 34 25 if ("usedinrelations".equals(keyword)) { 26 return new UsedInRelationsMatch(tokenizer); 27 } else 28 if ("parents".equals(keyword)) { 29 return new ParentsMatch(tokenizer); 30 } else 31 if ("children".equals(keyword)) { 32 return new ChildrenMatch(tokenizer); 33 } else 34 return null; 35 } 35 36 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UtilsUnaryMatchFactory.java
r30384 r32410 1 // License: GPL v2 or later. See LICENSE filefor details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.search; 3 3 4 4 import java.util.Arrays; 5 5 import java.util.Collection; 6 6 7 import org.openstreetmap.josm.actions.search.PushbackTokenizer; 7 8 import org.openstreetmap.josm.actions.search.SearchCompiler; … … 13 14 14 15 @Override 15 public SearchCompiler.UnaryMatch get(String keyword, SearchCompiler.Match matchOperand, PushbackTokenizer tokenizer) throws SearchCompiler.ParseError { 16 public SearchCompiler.UnaryMatch get(String keyword, SearchCompiler.Match matchOperand, PushbackTokenizer tokenizer) 17 throws SearchCompiler.ParseError { 16 18 if ("inside".equals(keyword)) { 17 19 return new InsideMatch(matchOperand); … … 24 26 } else if ("allintersecting".equals(keyword)) { 25 27 return new IntersectingMatch(matchOperand, true); 26 } 28 } 27 29 return null; 28 30 } … … 32 34 return keywords; 33 35 } 34 35 36 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentNodesAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 10 10 import java.util.HashSet; 11 11 import java.util.Set; 12 12 13 import org.openstreetmap.josm.actions.JosmAction; 13 import org.openstreetmap.josm.data.osm.*; 14 14 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.openstreetmap.josm.data.osm.Node; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.data.osm.Way; 15 18 import org.openstreetmap.josm.tools.Shortcut; 16 19 17 20 /** 18 * 21 * Extends current selection 19 22 */ 20 23 public class AdjacentNodesAction extends JosmAction { … … 24 27 public AdjacentNodesAction() { 25 28 super(tr("Adjacent nodes"), "adjnodes", tr("Select adjacent nodes"), 26 Shortcut.registerShortcut("tools:adjnodes", tr("Tool: {0}","Adjacent nodes"), 27 KeyEvent.VK_E, Shortcut.DIRECT), true); 29 Shortcut.registerShortcut("tools:adjnodes", tr("Tool: {0}", "Adjacent nodes"), 30 KeyEvent.VK_E, Shortcut.DIRECT), true); 28 31 putValue("help", ht("/Action/AdjacentNodes")); 29 32 } 30 33 31 private 34 private Set<Way> activeWays = new HashSet<>(); 32 35 33 36 @Override … … 38 41 39 42 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(ds.getSelected(), Way.class); 40 43 41 44 // if no nodes and no ways are selected, do nothing 42 45 if (selectedNodes.isEmpty() && selectedWays.isEmpty()) return; … … 50 53 if (selectedNodes.size() == 1) { 51 54 activeWays.clear(); 52 // System.out.println("Cleared active ways"); 55 // System.out.println("Cleared active ways"); 53 56 } 54 57 } else { … … 58 61 59 62 // selecting nodes of selected ways 60 if(selectedNodes.isEmpty()) { 63 if (selectedNodes.isEmpty()) { 61 64 HashSet<Node> newNodes = new HashSet<>(); 62 65 NodeWayUtils.addNodesConnectedToWays(selectedWays, newNodes); … … 70 73 } 71 74 72 Set<Node> newNodes = new HashSet 75 Set<Node> newNodes = new HashSet<>(); 73 76 for (Node node: selectedNodes) { 74 77 for (Way w: activeWays) { … … 76 79 } 77 80 } 78 81 79 82 // select only newly found nodes 80 83 newNodes.removeAll(selectedNodes); 81 84 82 // System.out.printf("Found %d new nodes\n",newNodes.size()); 83 84 // enable branching on next call of this function 85 // if no new nodes were found, next search will include all touched ways 86 if (newNodes.isEmpty()) { 87 activeWays.clear(); 88 // System.out.println("No more points found, activeways cleared"); 89 } 85 // enable branching on next call of this function 86 // if no new nodes were found, next search will include all touched ways 87 if (newNodes.isEmpty()) { 88 activeWays.clear(); 89 } 90 90 91 91 ds.addSelected(newNodes); 92 92 } 93 93 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentWaysAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 10 10 import java.util.HashSet; 11 11 import java.util.Set; 12 12 13 import org.openstreetmap.josm.actions.JosmAction; 13 import org.openstreetmap.josm.data.osm.*; 14 14 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.openstreetmap.josm.data.osm.Node; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.data.osm.Way; 15 18 import org.openstreetmap.josm.tools.Shortcut; 16 19 17 20 /** 18 * 21 * Extends current selection 19 22 */ 20 23 public class AdjacentWaysAction extends JosmAction { … … 25 28 super(tr("Adjacent ways"), "adjways", 26 29 tr("Adjacent ways will be selected. Nodes will be deselected."), 27 Shortcut.registerShortcut("tools:adjways", tr("Tool: {0}","Adjacent ways"), 28 KeyEvent.VK_E, Shortcut.SHIFT), true); 30 Shortcut.registerShortcut("tools:adjways", tr("Tool: {0}", "Adjacent ways"), 31 KeyEvent.VK_E, Shortcut.SHIFT), true); 29 32 putValue("help", ht("/Action/AdjacentWays")); 30 33 } … … 44 47 45 48 // selecting ways attached to selected nodes 46 if(!selectedNodes.isEmpty()) { 49 if (!selectedNodes.isEmpty()) { 47 50 NodeWayUtils.addWaysConnectedToNodes(selectedNodes, newWays); 48 51 } 49 52 50 // System.out.printf("%d ways added to selection\n",newWays.size()-selectedWays.size()); 53 // System.out.printf("%d ways added to selection\n",newWays.size()-selectedWays.size()); 51 54 ds.setSelected(newWays); 52 55 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/ConnectedWaysAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 10 10 import java.util.HashSet; 11 11 import java.util.Set; 12 12 13 import org.openstreetmap.josm.actions.JosmAction; 13 import org.openstreetmap.josm.data.osm.*; 14 14 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.openstreetmap.josm.data.osm.Node; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.data.osm.Way; 15 18 import org.openstreetmap.josm.tools.Shortcut; 16 19 17 20 /** 18 * 21 * Extends current selection by selecting nodes on all touched ways 19 22 */ 20 23 public class ConnectedWaysAction extends JosmAction { … … 22 25 public ConnectedWaysAction() { 23 26 super(tr("All connected ways"), "adjwaysall", tr("Select all connected ways"), 24 Shortcut.registerShortcut("tools:adjwaysall", tr("Tool: {0}","All connected ways"), 25 KeyEvent.VK_E, Shortcut.CTRL_SHIFT), true); 27 Shortcut.registerShortcut("tools:adjwaysall", tr("Tool: {0}", "All connected ways"), 28 KeyEvent.VK_E, Shortcut.CTRL_SHIFT), true); 26 29 putValue("help", ht("/Action/SelectConnectedWays")); 27 30 } … … 37 40 38 41 // selecting ways attached to selected nodes 39 if(!selectedNodes.isEmpty()) { 42 if (!selectedNodes.isEmpty()) { 40 43 NodeWayUtils.addWaysConnectedToNodes(selectedNodes, newWays); 41 44 } … … 44 47 newWays.addAll(selectedWays); 45 48 NodeWayUtils.addWaysConnectedToWaysRecursively(selectedWays, newWays); 46 47 // System.out.printf("%d ways added to selection\n",newWays.size()-selectedWays.size()); 49 48 50 ds.setSelected(newWays); 49 51 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 21 21 22 22 /** 23 * 23 * Extends current selection by selecting nodes on all touched ways 24 24 */ 25 25 public class IntersectedWaysAction extends JosmAction { … … 27 27 public IntersectedWaysAction() { 28 28 super(tr("Intersecting ways"), "intway", tr("Select intersecting ways"), 29 Shortcut.registerShortcut("tools:intway", tr("Tool: {0}","Intersecting ways"), 30 KeyEvent.VK_I, Shortcut.DIRECT), true); 29 Shortcut.registerShortcut("tools:intway", tr("Tool: {0}", "Intersecting ways"), 30 KeyEvent.VK_I, Shortcut.DIRECT), true); 31 31 putValue("help", ht("/Action/SelectIntersectingWays")); 32 32 } … … 46 46 return; 47 47 } else { 48 49 tr("Please select some ways to find connected and intersecting ways!") 50 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 48 new Notification( 49 tr("Please select some ways to find connected and intersecting ways!") 50 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 51 51 } 52 52 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysRecursiveAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin ond others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 21 21 22 22 /** 23 * 23 * Extends current selection by selecting nodes on all touched ways 24 24 */ 25 25 public class IntersectedWaysRecursiveAction extends JosmAction { 26 26 27 27 public IntersectedWaysRecursiveAction() { 28 28 super(tr("All intersecting ways"), "intwayall", tr("Select all intersecting ways"), 29 Shortcut.registerShortcut("tools:intwayall", tr("Tool: {0}","All intersecting ways"), 30 KeyEvent.VK_MULTIPLY, Shortcut.CTRL), true); 29 Shortcut.registerShortcut("tools:intwayall", tr("Tool: {0}", "All intersecting ways"), 30 KeyEvent.VK_MULTIPLY, Shortcut.CTRL), true); 31 31 putValue("help", ht("/Action/SelectAllIntersectingWays")); 32 32 … … 45 45 ds.addSelected(newWays); 46 46 } else { 47 48 tr("Please select some ways to find all connected and intersecting ways!") 49 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 47 new Notification( 48 tr("Please select some ways to find all connected and intersecting ways!") 49 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 50 50 } 51 51 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/MiddleNodesAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 20 20 21 21 /** 22 * 22 * Selects nodes between two selected 23 23 */ 24 24 public class MiddleNodesAction extends JosmAction { … … 28 28 public MiddleNodesAction() { 29 29 super(tr("Middle nodes"), "midnodes", tr("Select middle nodes"), 30 Shortcut.registerShortcut("tools:midnodes", tr("Tool: {0}","Middle nodes"), 31 KeyEvent.VK_E, Shortcut.ALT_SHIFT), true); 30 Shortcut.registerShortcut("tools:midnodes", tr("Tool: {0}", "Middle nodes"), KeyEvent.VK_E, Shortcut.ALT_SHIFT), true); 32 31 putValue("help", ht("/Action/MiddleNodes")); 33 32 } … … 41 40 if (selectedNodes.size() != 2) { 42 41 new Notification( 43 tr("Please select two nodes connected by way!") 44 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 42 tr("Please select two nodes connected by way!") 43 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 45 44 return; 46 45 } 47 46 48 Set<Node> newNodes = new HashSet 47 Set<Node> newNodes = new HashSet<>(); 49 48 NodeWayUtils.addMiddle(selectedNodes, newNodes); 50 49 51 50 // select only newly found nodes 52 51 newNodes.removeAll(selectedNodes); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java
r30737 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 4 import org.openstreetmap.josm. data.osm.Relation;4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.util.ArrayList; 7 import java.util.Iterator;8 7 import java.util.Collection; 9 8 import java.util.HashSet; 9 import java.util.Iterator; 10 10 import java.util.List; 11 11 import java.util.Set; … … 19 19 import org.openstreetmap.josm.data.osm.Node; 20 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 import org.openstreetmap.josm.data.osm.Relation; 21 22 import org.openstreetmap.josm.data.osm.Way; 22 23 import org.openstreetmap.josm.gui.Notification; 23 24 import org.openstreetmap.josm.tools.Geometry; 24 25 import static org.openstreetmap.josm.tools.I18n.tr;26 27 25 import org.openstreetmap.josm.tools.Pair; 28 29 30 26 31 27 /** … … 38 34 static final int maxWays = Main.pref.getInteger("selection.maxfoundways", 2000); 39 35 static final int maxWays1 = Main.pref.getInteger("selection.maxfoundways.intersection", 500); 36 37 private NodeWayUtils() { 38 // Hide default constructor for utilities classes 39 } 40 40 41 41 /** … … 47 47 static void addNeighbours(Way w, Node n, Collection<Node> nodes) { 48 48 List<Node> nodeList = w.getNodes(); 49 49 50 50 int idx = nodeList.indexOf(n); 51 51 if (idx == -1) return; … … 68 68 } 69 69 } 70 70 } 71 71 72 72 /** … … 76 76 */ 77 77 static int addWaysConnectedToWay(Way w, Set<Way> ways) { 78 78 int s = ways.size(); 79 79 List<Node> nodes = w.getNodes(); 80 80 boolean flag = ways.contains(w); … … 103 103 * @param newWays set to place the ways we found 104 104 */ 105 static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays,Set<Way> excludeWays) { 105 static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays, Set<Way> excludeWays) { 106 106 List<Pair<Node, Node>> nodePairs = w.getNodePairs(false); 107 int count =0;107 int count = 0; 108 108 for (Way anyway: ways) { 109 109 if (anyway == w) continue; 110 if (newWays.contains(anyway) || excludeWays.contains(anyway) 110 if (newWays.contains(anyway) || excludeWays.contains(anyway)) continue; 111 111 112 112 List<Pair<Node, Node>> nodePairs2 = anyway.getNodePairs(false); 113 loop: for (Pair<Node,Node> p1 : nodePairs) { 114 for (Pair<Node,Node> p2 : nodePairs2) { 115 if (null !=Geometry.getSegmentSegmentIntersection(116 p1.a.getEastNorth(),p1.b.getEastNorth(), 117 p2.a.getEastNorth(),p2.b.getEastNorth())) { 118 119 120 113 loop: for (Pair<Node, Node> p1 : nodePairs) { 114 for (Pair<Node, Node> p2 : nodePairs2) { 115 if (null != Geometry.getSegmentSegmentIntersection( 116 p1.a.getEastNorth(), p1.b.getEastNorth(), 117 p2.a.getEastNorth(), p2.b.getEastNorth())) { 118 newWays.add(anyway); 119 count++; 120 break loop; 121 121 } 122 122 } … … 126 126 } 127 127 128 129 static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays) { 128 static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays) { 130 129 List<Pair<Node, Node>> nodePairs = w.getNodePairs(false); 131 int count =0;130 int count = 0; 132 131 for (Way anyway: ways) { 133 132 if (anyway == w) continue; 134 133 if (newWays.contains(anyway)) continue; 135 134 List<Pair<Node, Node>> nodePairs2 = anyway.getNodePairs(false); 136 loop: for (Pair<Node,Node> p1 : nodePairs) { 137 for (Pair<Node,Node> p2 : nodePairs2) { 138 if (null !=Geometry.getSegmentSegmentIntersection(139 p1.a.getEastNorth(),p1.b.getEastNorth(), 140 p2.a.getEastNorth(),p2.b.getEastNorth())) { 141 142 143 135 loop: for (Pair<Node, Node> p1 : nodePairs) { 136 for (Pair<Node, Node> p2 : nodePairs2) { 137 if (null != Geometry.getSegmentSegmentIntersection( 138 p1.a.getEastNorth(), p1.b.getEastNorth(), 139 p2.a.getEastNorth(), p2.b.getEastNorth())) { 140 newWays.add(anyway); 141 count++; 142 break loop; 144 143 } 145 144 } … … 156 155 */ 157 156 public static int addWaysIntersectingWays(Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) { 158 int count =0;159 for (Way w : initWays){ 160 count +=addWaysIntersectingWay(allWays, w, newWays);157 int count = 0; 158 for (Way w : initWays) { 159 count += addWaysIntersectingWay(allWays, w, newWays); 161 160 } 162 161 return count; 163 162 } 164 163 165 164 public static void addWaysConnectedToWays(Collection<Way> ways, Set<Way> newWays) { 166 for (Way w : ways){ 165 for (Way w : ways) { 167 166 NodeWayUtils.addWaysConnectedToWay(w, newWays); 168 167 } … … 185 184 } 186 185 187 public static void addWaysIntersectingWaysRecursively 188 (Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) { 186 public static void addWaysIntersectingWaysRecursively(Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) { 189 187 Set<Way> foundWays = new HashSet<>(); 190 188 foundWays.addAll(initWays); … … 192 190 Set<Way> newFoundWays; 193 191 194 int level =0,c;192 int level = 0, c; 195 193 do { 196 c=0; 197 newFoundWays = new HashSet<>(); 198 for (Way w : foundWays){ 199 c+=addWaysIntersectingWay(allWays, w, newFoundWays,newWays); 200 } 201 foundWays = newFoundWays; 202 newWays.addAll(newFoundWays); 203 level++; 204 // System.out.printf("%d: %d ways added to selection intersectiong\n",level,c); 205 if (c>maxWays1) { 206 new Notification( 207 tr("Too many ways are added: {0}!",c) 208 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 209 return; 210 } 211 } while ( c >0 && level < maxLevel ); 212 } 213 214 public static void addWaysConnectedToWaysRecursively 215 (Collection<Way> initWays, Set<Way> newWays) 216 { 217 //long t = System.currentTimeMillis(); 218 int level=0,c; 194 c = 0; 195 newFoundWays = new HashSet<>(); 196 for (Way w : foundWays) { 197 c += addWaysIntersectingWay(allWays, w, newFoundWays, newWays); 198 } 199 foundWays = newFoundWays; 200 newWays.addAll(newFoundWays); 201 level++; 202 if (c > maxWays1) { 203 new Notification( 204 tr("Too many ways are added: {0}!", c) 205 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 206 return; 207 } 208 } while (c > 0 && level < maxLevel); 209 } 210 211 public static void addWaysConnectedToWaysRecursively(Collection<Way> initWays, Set<Way> newWays) { 212 int level = 0, c; 219 213 newWays.addAll(initWays); 220 214 do { 221 c=0; 222 Set<Way> foundWays = new HashSet<>(); 223 foundWays.addAll(newWays); 224 for (Way w : foundWays){ 225 c+=addWaysConnectedToWay(w, newWays); 226 } 227 level++; 228 // System.out.printf("%d: %d ways added to selection\n",level,c); 229 if (c>maxWays) { 215 c = 0; 216 Set<Way> foundWays = new HashSet<>(); 217 foundWays.addAll(newWays); 218 for (Way w : foundWays) { 219 c += addWaysConnectedToWay(w, newWays); 220 } 221 level++; 222 if (c > maxWays) { 230 223 new Notification( 231 tr("Too many ways are added: {0}!",c) 232 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 233 return; 234 } 235 } while ( c >0 && level < maxLevel ); 236 // System.out.println("time = "+(System.currentTimeMillis()-t)+" ways = "+newWays.size()); 224 tr("Too many ways are added: {0}!", c) 225 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 226 return; 227 } 228 } while (c > 0 && level < maxLevel); 237 229 } 238 230 239 231 static void addMiddle(Set<Node> selectedNodes, Set<Node> newNodes) { 240 Iterator<Node> it =selectedNodes.iterator();232 Iterator<Node> it = selectedNodes.iterator(); 241 233 Node n1 = it.next(); 242 234 Node n2 = it.next(); 243 Set<Way> ways =new HashSet<>();235 Set<Way> ways = new HashSet<>(); 244 236 ways.addAll(OsmPrimitive.getFilteredList(n1.getReferrers(), Way.class)); 245 237 for (Way w: ways) { … … 247 239 if (w.isUsable() && w.containsNode(n2) && w.containsNode(n1)) { 248 240 // Way w goes from n1 to n2 249 List 241 List<Node> nodes = w.getNodes(); 250 242 int i1 = nodes.indexOf(n1); 251 243 int i2 = nodes.indexOf(n2); 252 244 int n = nodes.size(); 253 if (i1>i2) { int p=i2; i2=i1; i1=p; } // now i1<i2 245 if (i1 > i2) { 246 int p = i2; i2 = i1; i1 = p; // now i1<i2 247 } 254 248 if (w.isClosed()) { 255 if ((i2-i1)*2 <= n ) { // i1 ... i2 256 for (int i=i1+1;i!=i2; i++) { 257 newNodes.add(nodes.get(i)); 258 } 259 } else { // i2 ... n-1 0 1 ... i1 260 for (int i=i2+1;i!=i1; i=(i+1)%n) { 261 newNodes.add(nodes.get(i)); 262 } 263 } 264 } else { 265 for (int i=i1+1;i<i2;i++) { 249 if ((i2-i1)*2 <= n) { // i1 ... i2 250 for (int i = i1+1; i != i2; i++) { 266 251 newNodes.add(nodes.get(i)); 267 252 } 268 } 253 } else { // i2 ... n-1 0 1 ... i1 254 for (int i = i2+1; i != i1; i = (i+1) % n) { 255 newNodes.add(nodes.get(i)); 256 } 257 } 258 } else { 259 for (int i = i1+1; i < i2; i++) { 260 newNodes.add(nodes.get(i)); 261 } 262 } 269 263 } 270 264 } 271 265 if (newNodes.isEmpty()) { 272 266 new Notification( 273 267 tr("Please select two nodes connected by way!") 274 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 275 276 } 277 268 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 269 } 270 } 271 278 272 static boolean addAreaBoundary(Way firstWay, Set<Way> newWays, boolean goingLeft) { 279 Way w =firstWay;273 Way w = firstWay; 280 274 Node curNode = w.lastNode(); 281 275 Node prevNode = w.getNode(w.getNodes().size()-2); 282 276 Set<Way> newestWays = new HashSet<>(); 283 while(true) { 277 while (true) { 284 278 285 279 Node nextNode, endNode, otherEnd, preLast; … … 287 281 288 282 EastNorth en; 289 double startHeading,bestAngle; 283 double startHeading, bestAngle; 290 284 291 285 en = curNode.getEastNorth(); 292 startHeading = prevNode.getEastNorth().heading( en ); 293 294 bestAngle = goingLeft ? -1e5 : 1e5 ; 295 otherEnd=null; nextWay=null; 296 286 startHeading = prevNode.getEastNorth().heading(en); 287 288 bestAngle = goingLeft ? -1e5 : 1e5; 289 otherEnd = null; 290 nextWay = null; 291 297 292 for (OsmPrimitive ref : curNode.getReferrers()) { 298 if (ref instanceof Way && ref !=w && ref.isSelectable()) {293 if (ref instanceof Way && ref != w && ref.isSelectable()) { 299 294 // 300 295 Way w2 = (Way) ref; 301 296 // -----[prevNode]-(curNode)-[nextNode]------[preLast]-(endNode) 302 297 // w | w2 303 if (w2.getNodesCount()<2 || w2.isClosed()) continue; 304 298 if (w2.getNodesCount() < 2 || w2.isClosed()) continue; 305 299 306 300 if (curNode == w2.firstNode()) { 307 301 nextNode = w2.getNode(1); 308 302 preLast = w2.getNode(w2.getNodesCount()-2); 309 endNode = w2.lastNode(); 310 } // forward direction 311 else if (curNode == w2.lastNode()) { 303 endNode = w2.lastNode(); // forward direction 304 } else if (curNode == w2.lastNode()) { 312 305 nextNode = w2.getNode(w2.getNodesCount()-2); 313 306 preLast = w2.getNode(1); 314 endNode = w2.firstNode(); 315 } // backward direction 316 else continue; // we came to some way middle node 307 endNode = w2.firstNode(); // backward direction 308 } else continue; // we came to some way middle node 317 309 318 310 double angle = startHeading -Math.PI - en.heading(nextNode.getEastNorth()); 319 while (angle<0) angle+=2*Math.PI; 320 311 while (angle < 0) { 312 angle += 2*Math.PI; 313 } 314 321 315 if (angle < bestAngle ^ goingLeft) { 322 316 bestAngle = angle; … … 327 321 } 328 322 } 329 if (firstWay == nextWay 330 //we came to starting way, but not not the right end 331 if (otherEnd ==firstWay.firstNode()) return false;323 if (firstWay == nextWay) { 324 //we came to starting way, but not not the right end 325 if (otherEnd == firstWay.firstNode()) return false; 332 326 newWays.addAll(newestWays); 333 return true; // correct loop found 327 return true; // correct loop found 334 328 } 335 329 if (newestWays.contains(nextWay)) { … … 337 331 return false; 338 332 } 339 if (nextWay != null) { 333 if (nextWay != null) { 340 334 newestWays.add(nextWay); 341 335 curNode = otherEnd; … … 345 339 // no closed loop found 346 340 return false; 347 } 348 } 349 } 350 341 } 342 } 343 } 344 351 345 static boolean isPointInsideMultipolygon(EastNorth p, Relation rel) { 352 346 Set<Way> usedWays = OsmPrimitive.getFilteredSet(rel.getMemberPrimitives(), Way.class); 353 347 return isPointInsidePolygon(p, buildPointList(usedWays)); 354 348 } 355 349 356 350 static void addAllInsideMultipolygon(DataSet data, Relation rel, Set<Way> newWays, Set<Node> newNodes) { 357 351 if (!rel.isMultipolygon()) return; … … 359 353 Collection<Way> usedWays = rel.getMemberPrimitives(Way.class); 360 354 List<EastNorth> polyPoints = buildPointList(usedWays); 361 355 362 356 List<Node> searchNodes = data.searchNodes(box); 363 357 Set<Node> newestNodes = new HashSet<>(); … … 369 363 } 370 364 } 371 365 372 366 List<Way> searchWays = data.searchWays(box); 373 367 for (Way w : searchWays) { … … 380 374 // do not select nodes of already selected ways 381 375 } 382 376 383 377 newNodes.addAll(newestNodes); 384 378 newWays.addAll(newestWays); … … 389 383 BBox box = way.getBBox(); 390 384 Iterable<EastNorth> polyPoints = getWayPoints(way); 391 385 392 386 List<Node> searchNodes = data.searchNodes(box); 393 387 Set<Node> newestNodes = new HashSet<>(); … … 399 393 } 400 394 } 401 395 402 396 List<Way> searchWays = data.searchWays(box); 403 397 for (Way w : searchWays) { … … 406 400 } 407 401 } 408 402 409 403 newNodes.addAll(newestNodes); 410 404 newWays.addAll(newestWays); 411 405 } 412 406 413 407 public static boolean isPointInsidePolygon(EastNorth point, Iterable<EastNorth> polygonPoints) { 414 408 int n = getRayIntersectionsCount(point, polygonPoints); 415 if (n <0) return true; // we are near node or near edge416 return (n %2==1);409 if (n < 0) return true; // we are near node or near edge 410 return (n % 2 == 1); 417 411 } 418 412 … … 423 417 */ 424 418 public static int getRayIntersectionsCount(EastNorth point, Iterable<EastNorth> polygonPoints) { 425 if (point ==null) return 0;419 if (point == null) return 0; 426 420 EastNorth oldPoint = null; 427 double n1, n2,n3,e1,e2,e3,d;428 int interCount =0;429 421 double n1, n2, n3, e1, e2, e3, d; 422 int interCount = 0; 423 430 424 for (EastNorth curPoint : polygonPoints) { 431 if (oldPoint ==null || curPoint==null) {425 if (oldPoint == null || curPoint == null) { 432 426 oldPoint = curPoint; 433 427 continue; 434 428 } 435 n1 = curPoint.north(); n2 = oldPoint.north(); n3 =point.north();436 e1 = curPoint.east(); e2 = oldPoint.east(); e3 =point.east();437 438 if (Math.abs(n1-n3) <1e-5 && Math.abs(e1-e3)<1e-5) return -3; // vertex439 if (Math.abs(n2-n3) <1e-5 && Math.abs(e2-e3)<1e-5) return -3; // vertex440 429 n1 = curPoint.north(); n2 = oldPoint.north(); n3 = point.north(); 430 e1 = curPoint.east(); e2 = oldPoint.east(); e3 = point.east(); 431 432 if (Math.abs(n1-n3) < 1e-5 && Math.abs(e1-e3) < 1e-5) return -3; // vertex 433 if (Math.abs(n2-n3) < 1e-5 && Math.abs(e2-e3) < 1e-5) return -3; // vertex 434 441 435 // looking at oldPoint-curPoint segment 442 if ( 436 if (n1 > n2) { 443 437 if (n1 > n3 && n3 >= n2) { 444 n1 -=n3; n2-=n3; e1-=e3; e2-=e3;438 n1 -= n3; n2 -= n3; e1 -= e3; e2 -= e3; 445 439 d = e1*n2 - n1*e2; 446 if (d <-1e-5) {447 interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >=0 448 } else if (d <=1e-5) return -2; // boundary detected440 if (d < -1e-5) { 441 interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >= 0 442 } else if (d <= 1e-5) return -2; // boundary detected 449 443 } 450 444 } else if (n1 == n2) { 451 445 if (n1 == n3) { 452 e1 -=e3; e2-=e3;453 if ((e1 <=0 && e2 >= 0) || (e1 >=0 && e2 <= 0)) return -2;// boundary detected 446 e1 -= e3; e2 -= e3; 447 if ((e1 <= 0 && e2 >= 0) || (e1 >= 0 && e2 <= 0)) return -2; // boundary detected 454 448 } 455 449 } else { 456 450 if (n1 <= n3 && n3 < n2) { 457 n1 -=n3; n2-=n3; e1-=e3; e2-=e3;451 n1 -= n3; n2 -= n3; e1 -= e3; e2 -= e3; 458 452 d = e1*n2 - n1*e2; 459 if (d >1e-5) {460 interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >=0 461 } else if (d >=-1e-5) return -2; // boundary detected453 if (d > 1e-5) { 454 interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >= 0 455 } else if (d >= -1e-5) return -2; // boundary detected 462 456 } 463 457 } … … 467 461 return interCount; 468 462 } 469 463 470 464 public static Collection<OsmPrimitive> selectAllInside(Collection<OsmPrimitive> selected, DataSet dataset) { 471 465 return selectAllInside(selected, dataset, true); 472 466 } 473 467 474 468 public static Collection<OsmPrimitive> selectAllInside(Collection<OsmPrimitive> selected, DataSet dataset, boolean ignoreNodesOfFoundWays) { 475 469 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(selected, Way.class); … … 488 482 if (!selectedWays.isEmpty()) { 489 483 for (Way w: selectedWays) { 490 addAllInsideWay(dataset, w,newWays,newNodes);484 addAllInsideWay(dataset, w, newWays, newNodes); 491 485 } 492 486 } 493 487 if (!selectedRels.isEmpty()) { 494 488 for (Relation r: selectedRels) { 495 addAllInsideMultipolygon(dataset, r,newWays,newNodes);489 addAllInsideMultipolygon(dataset, r, newWays, newNodes); 496 490 } 497 491 } … … 500 494 newNodes.removeAll(w.getNodes()); 501 495 // do not select nodes of already selected ways 502 } 503 } 504 496 } 497 } 498 505 499 Set<OsmPrimitive> insideSelection = new HashSet<>(); 506 500 if (!newWays.isEmpty() || !newNodes.isEmpty()) { … … 521 515 return points; 522 516 } 523 517 524 518 public static Iterable<EastNorth> getWayPoints(final Way w) { 525 519 return new Iterable<EastNorth>() { … … 531 525 return idx < w.getNodesCount(); 532 526 } 527 533 528 @Override public EastNorth next() { 534 529 return w.getNode(idx++).getEastNorth(); 535 530 } 531 536 532 @Override public void remove() { 537 533 throw new UnsupportedOperationException(); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectAllInsideAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 18 18 19 19 /** 20 * 20 * Extends current selection by selecting nodes on all touched ways 21 21 */ 22 22 public class SelectAllInsideAction extends JosmAction { … … 24 24 public SelectAllInsideAction() { 25 25 super(tr("All inside [testing]"), "selinside", tr("Select all inside selected polygons"), 26 Shortcut.registerShortcut("tools:selinside", tr("Tool: {0}","All inside"), 27 KeyEvent.VK_I, Shortcut.ALT_SHIFT), true); 26 Shortcut.registerShortcut("tools:selinside", tr("Tool: {0}", "All inside"), 27 KeyEvent.VK_I, Shortcut.ALT_SHIFT), true); 28 28 putValue("help", ht("/Action/SelectAllInside")); 29 29 } 30 30 31 31 @Override 32 32 public void actionPerformed(ActionEvent e) { 33 33 DataSet ds = getLayerManager().getEditDataSet(); 34 34 Collection<OsmPrimitive> insideSelected = NodeWayUtils.selectAllInside(ds.getSelected(), ds, true); 35 35 36 36 if (!insideSelected.isEmpty()) { 37 37 ds.addSelected(insideSelected); 38 } else{ 38 } else { 39 39 new Notification( 40 tr("Nothing found. Please select some closed ways or multipolygons to find all primitives inside them!")) 41 42 .show();40 tr("Nothing found. Please select some closed ways or multipolygons to find all primitives inside them!")) 41 .setIcon(JOptionPane.WARNING_MESSAGE) 42 .show(); 43 43 } 44 44 } … … 57 57 setEnabled(!selection.isEmpty()); 58 58 } 59 60 61 59 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectBoundaryAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 4 import java.awt.Point;5 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 6 5 import static org.openstreetmap.josm.tools.I18n.tr; 7 6 7 import java.awt.Point; 8 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.KeyEvent; … … 13 13 14 14 import javax.swing.JOptionPane; 15 15 16 import org.openstreetmap.josm.Main; 16 17 17 import org.openstreetmap.josm.actions.JosmAction; 18 18 import org.openstreetmap.josm.actions.SelectByInternalPointAction; … … 21 21 import org.openstreetmap.josm.data.osm.Way; 22 22 import org.openstreetmap.josm.gui.Notification; 23 24 23 import org.openstreetmap.josm.tools.Shortcut; 25 24 26 25 /** 27 * 26 * Extends current selection by selecting nodes on all touched ways 28 27 */ 29 28 public class SelectBoundaryAction extends JosmAction { … … 33 32 public SelectBoundaryAction() { 34 33 super(tr("Area boundary [testing]"), "selboundary", tr("Select relation or all ways that forms area boundary"), 35 Shortcut.registerShortcut("tools:selboundary", tr("Tool: {0}","Area boundary [testing]"), 36 KeyEvent.VK_SLASH, Shortcut.SHIFT), true); 34 Shortcut.registerShortcut("tools:selboundary", tr("Tool: {0}", "Area boundary [testing]"), 35 KeyEvent.VK_SLASH, Shortcut.SHIFT), true); 37 36 putValue("help", ht("/Action/SelectAreaBoundary")); 38 37 } … … 42 41 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(getLayerManager().getEditDataSet().getSelected(), Way.class); 43 42 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(getLayerManager().getEditDataSet().getSelected(), Node.class); 44 43 45 44 Set<Way> newWays = new HashSet<>(); 46 47 Way w =null;48 45 46 Way w = null; 47 49 48 if (selectedWays.isEmpty()) { 50 if (selectedNodes.size() ==1) {49 if (selectedNodes.size() == 1) { 51 50 for (OsmPrimitive p : selectedNodes.iterator().next().getReferrers()) { 52 51 if (p instanceof Way && p.isSelectable()) { 53 //if (w!=null) return; // if we want only one way 54 w=(Way) p; 52 w = (Way) p; 55 53 break; 56 54 } … … 61 59 return; 62 60 } 63 } else if (selectedWays.size() ==1){61 } else if (selectedWays.size() == 1) { 64 62 w = selectedWays.iterator().next(); 65 } else if (selectedWays.contains(lastUsedStartingWay)) { 66 w =lastUsedStartingWay; //repeated call for selected way63 } else if (selectedWays.contains(lastUsedStartingWay)) { 64 w = lastUsedStartingWay; //repeated call for selected way 67 65 lastUsedLeft = !lastUsedLeft; 68 66 } 69 67 70 71 if (w ==null) return; //no starting way found68 69 if (w == null) return; //no starting way found 72 70 if (!w.isSelectable()) return; 73 71 if (w.isClosed()) return; 74 if (w.getNodesCount() <2) return;72 if (w.getNodesCount() < 2) return; 75 73 76 74 newWays.add(w); 77 75 lastUsedStartingWay = w; 78 76 79 77 // try going left at each turn 80 if (! 78 if (!NodeWayUtils.addAreaBoundary(w, newWays, lastUsedLeft)) { 81 79 NodeWayUtils.addAreaBoundary(w, newWays, !lastUsedLeft); // try going right at each turn 82 80 } 83 84 if (!newWays.isEmpty() 81 82 if (!newWays.isEmpty()) { 85 83 getLayerManager().getEditDataSet().setSelected(newWays); 86 } else{ 84 } else { 87 85 new Notification(tr("Nothing found. Please select way that is a part of some polygon formed by connected ways")) 88 86 .setIcon(JOptionPane.WARNING_MESSAGE).show(); 89 87 } 90 88 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectHighwayAction.java
r32333 r32410 1 // License: PD1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 28 28 * Select all connected ways for a street if one way is selected (determine by name/ref), 29 29 * select highway ways between two selected ways. 30 * 30 * 31 31 * @author zverik 32 32 */ … … 35 35 public SelectHighwayAction() { 36 36 super(tr("Select Highway"), "selecthighway", tr("Select highway for the name/ref given"), 37 Shortcut.registerShortcut("tools:selecthighway", tr("Tool: {0}","Select Highway"), 38 KeyEvent.VK_W, Shortcut.ALT_CTRL), true); 37 Shortcut.registerShortcut("tools:selecthighway", tr("Tool: {0}", "Select Highway"), 38 KeyEvent.VK_W, Shortcut.ALT_CTRL), true); 39 39 } 40 40 … … 44 44 List<Way> selectedWays = OsmPrimitive.getFilteredList(ds.getSelected(), Way.class); 45 45 46 if (selectedWays.size() == 146 if (selectedWays.size() == 1) { 47 47 ds.setSelected(selectNamedRoad(selectedWays.get(0))); 48 } else if (selectedWays.size() == 248 } else if (selectedWays.size() == 2) { 49 49 ds.setSelected(selectHighwayBetween(selectedWays.get(0), selectedWays.get(1))); 50 50 } else { 51 51 new Notification( 52 tr("Please select one or two ways for this action") 53 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 54 } 55 } 56 57 private Set<Way> selectNamedRoad( 52 tr("Please select one or two ways for this action") 53 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 54 } 55 } 56 57 private Set<Way> selectNamedRoad(Way firstWay) { 58 58 Set<Way> newWays = new HashSet<>(); 59 59 String key = firstWay.hasKey("name") ? "name" : "ref"; 60 if (firstWay.hasKey(key)60 if (firstWay.hasKey(key)) { 61 61 String value = firstWay.get(key); 62 62 Queue<Node> nodeQueue = new LinkedList<>(); 63 63 nodeQueue.add(firstWay.firstNode()); 64 while (!nodeQueue.isEmpty()64 while (!nodeQueue.isEmpty()) { 65 65 Node node = nodeQueue.remove(); 66 for (Way p : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)67 if (!newWays.contains(p) && p.hasKey(key) && p.get(key).equals(value)66 for (Way p : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) { 67 if (!newWays.contains(p) && p.hasKey(key) && p.get(key).equals(value)) { 68 68 newWays.add(p); 69 69 nodeQueue.add(p.firstNode().equals(node) ? p.lastNode() : p.firstNode()); … … 74 74 return newWays; 75 75 } 76 77 private Set<Way> selectHighwayBetween( 76 77 private Set<Way> selectHighwayBetween(Way firstWay, Way lastWay) { 78 78 int minRank = Math.min(getHighwayRank(firstWay), getHighwayRank(lastWay)); 79 80 81 82 while(intersection == null && (firstTree.canMoveOn() || secondTree.canMoveOn())83 84 85 86 87 88 89 90 91 } 92 93 private static int getHighwayRank( 94 if (!way.hasKey("highway")79 HighwayTree firstTree = new HighwayTree(firstWay, minRank); 80 HighwayTree secondTree = new HighwayTree(lastWay, minRank); 81 Way intersection = firstTree.getIntersection(secondTree); 82 while (intersection == null && (firstTree.canMoveOn() || secondTree.canMoveOn())) { 83 firstTree.processNextLevel(); 84 secondTree.processNextLevel(); 85 intersection = firstTree.getIntersection(secondTree); 86 } 87 Set<Way> newWays = new HashSet<>(); 88 newWays.addAll(firstTree.getPath(intersection)); 89 newWays.addAll(secondTree.getPath(intersection)); 90 return newWays; 91 } 92 93 private static int getHighwayRank(OsmPrimitive way) { 94 if (!way.hasKey("highway")) 95 95 return 0; 96 96 String highway = way.get("highway"); 97 if (highway.equals("path") || highway.equals("footway") || highway.equals("cycleway")97 if (highway.equals("path") || highway.equals("footway") || highway.equals("cycleway")) 98 98 return 1; 99 else if (highway.equals("track") || highway.equals("service")99 else if (highway.equals("track") || highway.equals("service")) 100 100 return 2; 101 else if (highway.equals("unclassified") || highway.equals("residential")101 else if (highway.equals("unclassified") || highway.equals("residential")) 102 102 return 3; 103 else if (highway.equals("tertiary") || highway.equals("tertiary_link")103 else if (highway.equals("tertiary") || highway.equals("tertiary_link")) 104 104 return 4; 105 else if (highway.equals("secondary") || highway.equals("secondary_link")105 else if (highway.equals("secondary") || highway.equals("secondary_link")) 106 106 return 5; 107 else if (highway.equals("primary") || highway.equals("primary_link")107 else if (highway.equals("primary") || highway.equals("primary_link")) 108 108 return 6; 109 else if (highway.equals("trunk") || highway.equals("trunk_link") || highway.equals("motorway") || highway.equals("motorway_link")109 else if (highway.equals("trunk") || highway.equals("trunk_link") || highway.equals("motorway") || highway.equals("motorway_link")) 110 110 return 7; 111 111 return 0; 112 112 } 113 113 114 114 @Override 115 115 protected void updateEnabledState() { … … 124 124 } 125 125 int count = 0, rank = 100; 126 for (OsmPrimitive p : selection127 if (p instanceof Way126 for (OsmPrimitive p : selection) { 127 if (p instanceof Way) { 128 128 count++; 129 129 rank = Math.min(rank, getHighwayRank(p)); … … 132 132 setEnabled(count == 1 || (count == 2 && rank > 0)); 133 133 } 134 134 135 135 private static class HighwayTree { 136 private List<Way> tree; 137 private List<Integer> refs; 138 private List<Node> nodesToCheck; 139 private List<Integer> nodeRefs; 140 private int minHighwayRank; 141 142 public HighwayTree( Way from, int minHighwayRank ) { 143 tree = new ArrayList<>(1); 144 refs = new ArrayList<>(1); 145 tree.add(from); 146 refs.add(Integer.valueOf(-1)); 147 this.minHighwayRank = minHighwayRank; 148 nodesToCheck = new ArrayList<>(2); 149 nodeRefs = new ArrayList<>(2); 150 nodesToCheck.add(from.firstNode()); 151 nodesToCheck.add(from.lastNode()); 152 nodeRefs.add(Integer.valueOf(0)); 153 nodeRefs.add(Integer.valueOf(0)); 154 } 155 156 public void processNextLevel() { 157 List<Node> newNodes = new ArrayList<>(); 158 List<Integer> newIdx = new ArrayList<>(); 159 for( int i = 0; i < nodesToCheck.size(); i++ ) { 160 Node node = nodesToCheck.get(i); 161 Integer nodeRef = nodeRefs.get(i); 162 for( Way way : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class) ) { 163 if( (way.firstNode().equals(node) || way.lastNode().equals(node)) && 164 !tree.contains(way) && suits(way) ) { 165 tree.add(way); 166 refs.add(nodeRef); 167 Node newNode = way.firstNode().equals(node) ? way.lastNode() : way.firstNode(); 168 newNodes.add(newNode); 169 newIdx.add(Integer.valueOf(tree.size() - 1)); 170 } 171 } 172 } 173 nodesToCheck = newNodes; 174 nodeRefs = newIdx; 175 } 176 177 private boolean suits( Way w ) { 178 return getHighwayRank(w) >= minHighwayRank; 179 } 180 181 public boolean canMoveOn() { 182 return !nodesToCheck.isEmpty() && tree.size() < 10000; 183 } 184 185 public Way getIntersection( HighwayTree other ) { 186 for( Way w : other.tree ) 187 if( tree.contains(w) ) 188 return w; 189 return null; 190 } 191 192 public List<Way> getPath( Way to ) { 193 if( to == null ) 194 return Collections.singletonList(tree.get(0)); 195 int pos = tree.indexOf(to); 196 if( pos < 0 ) 197 throw new ArrayIndexOutOfBoundsException("Way " + to + " is not in the tree."); 198 List<Way> result = new ArrayList<>(1); 199 while( pos >= 0 ) { 200 result.add(tree.get(pos)); 201 pos = refs.get(pos); 202 } 203 return result; 204 } 136 private List<Way> tree; 137 private List<Integer> refs; 138 private List<Node> nodesToCheck; 139 private List<Integer> nodeRefs; 140 private int minHighwayRank; 141 142 HighwayTree(Way from, int minHighwayRank) { 143 tree = new ArrayList<>(1); 144 refs = new ArrayList<>(1); 145 tree.add(from); 146 refs.add(Integer.valueOf(-1)); 147 this.minHighwayRank = minHighwayRank; 148 nodesToCheck = new ArrayList<>(2); 149 nodeRefs = new ArrayList<>(2); 150 nodesToCheck.add(from.firstNode()); 151 nodesToCheck.add(from.lastNode()); 152 nodeRefs.add(Integer.valueOf(0)); 153 nodeRefs.add(Integer.valueOf(0)); 154 } 155 156 public void processNextLevel() { 157 List<Node> newNodes = new ArrayList<>(); 158 List<Integer> newIdx = new ArrayList<>(); 159 for (int i = 0; i < nodesToCheck.size(); i++) { 160 Node node = nodesToCheck.get(i); 161 Integer nodeRef = nodeRefs.get(i); 162 for (Way way : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) { 163 if ((way.firstNode().equals(node) || way.lastNode().equals(node)) && 164 !tree.contains(way) && suits(way)) { 165 tree.add(way); 166 refs.add(nodeRef); 167 Node newNode = way.firstNode().equals(node) ? way.lastNode() : way.firstNode(); 168 newNodes.add(newNode); 169 newIdx.add(Integer.valueOf(tree.size() - 1)); 170 } 171 } 172 } 173 nodesToCheck = newNodes; 174 nodeRefs = newIdx; 175 } 176 177 private boolean suits(Way w) { 178 return getHighwayRank(w) >= minHighwayRank; 179 } 180 181 public boolean canMoveOn() { 182 return !nodesToCheck.isEmpty() && tree.size() < 10000; 183 } 184 185 public Way getIntersection(HighwayTree other) { 186 for (Way w : other.tree) { 187 if (tree.contains(w)) 188 return w; 189 } 190 return null; 191 } 192 193 public List<Way> getPath(Way to) { 194 if (to == null) 195 return Collections.singletonList(tree.get(0)); 196 int pos = tree.indexOf(to); 197 if (pos < 0) 198 throw new ArrayIndexOutOfBoundsException("Way " + to + " is not in the tree."); 199 List<Way> result = new ArrayList<>(1); 200 while (pos >= 0) { 201 result.add(tree.get(pos)); 202 pos = refs.get(pos); 203 } 204 return result; 205 } 205 206 } 206 207 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModNodesAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 4 import org.openstreetmap.josm.command.Command;5 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 6 5 import static org.openstreetmap.josm.tools.I18n.tr; … … 11 10 import java.util.HashSet; 12 11 import java.util.Set; 12 13 13 import org.openstreetmap.josm.Main; 14 14 import org.openstreetmap.josm.actions.JosmAction; 15 import org.openstreetmap.josm.data.osm.*; 16 15 import org.openstreetmap.josm.command.Command; 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 19 import org.openstreetmap.josm.tools.Shortcut; 18 20 19 21 /** 20 * 22 * Unselects all nodes 21 23 */ 22 24 public class SelectModNodesAction extends JosmAction { … … 27 29 super(tr("Select last modified nodes"), "selmodnodes", 28 30 tr("Select last modified nodes"), 29 Shortcut.registerShortcut("tools:selmodnodes", tr("Tool: {0}","Select last modified nodes"), 30 KeyEvent.VK_Z, Shortcut.SHIFT), true); 31 Shortcut.registerShortcut("tools:selmodnodes", tr("Tool: {0}", "Select last modified nodes"), 32 KeyEvent.VK_Z, Shortcut.SHIFT), true); 31 33 putValue("help", ht("/Action/SelectLastModifiedNodes")); 32 34 } 33 35 34 36 @Override 35 37 public void actionPerformed(ActionEvent e) { 36 38 DataSet ds = getLayerManager().getEditDataSet(); 37 39 Collection<OsmPrimitive> selection = ds.getSelected(); 38 40 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 39 41 ds.clearSelection(selectedNodes); 40 Command cmd =null; 42 Command cmd = null; 41 43 42 44 if (Main.main.undoRedo.commands == null) return; 43 int num =Main.main.undoRedo.commands.size();44 if (num ==0) return;45 int k =0,idx;46 if (selection !=null && !selection.isEmpty() && selection.hashCode() == lastHash) {45 int num = Main.main.undoRedo.commands.size(); 46 if (num == 0) return; 47 int k = 0, idx; 48 if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) { 47 49 // we are selecting next command in history if nothing is selected 48 50 idx = Main.main.undoRedo.commands.indexOf(lastCmd); 49 // System.out.println("My previous selection found "+idx);50 51 } else { 51 idx=num; 52 // System.out.println("last history item taken"); 52 idx = num; 53 53 } 54 54 55 55 Set<Node> nodes = new HashSet<>(10); 56 56 do { // select next history element 57 if (idx >0) idx--; else idx=num-1;57 if (idx > 0) idx--; else idx = num-1; 58 58 cmd = Main.main.undoRedo.commands.get(idx); 59 59 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 60 60 nodes.clear(); 61 for ( 62 if (p instanceof Node && !p.isDeleted()) nodes.add((Node)p); 61 for (OsmPrimitive p : pp) { // find all affected ways 62 if (p instanceof Node && !p.isDeleted()) nodes.add((Node) p); 63 63 } 64 64 if (!nodes.isEmpty()) { … … 67 67 lastHash = ds.getSelected().hashCode(); 68 68 return; 69 69 } 70 70 k++; 71 71 //System.out.println("no nodes found, previous..."); 72 } while ( k < num); // try to find previous command if this affects nothing73 lastCmd =null; lastHash=0;72 } while (k < num); // try to find previous command if this affects nothing 73 lastCmd = null; lastHash = 0; 74 74 } 75 75 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModWaysAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 import static org.openstreetmap.josm.tools.I18n.tr; 3 6 4 7 import java.awt.event.ActionEvent; … … 7 10 import java.util.HashSet; 8 11 import java.util.Set; 12 9 13 import org.openstreetmap.josm.Main; 10 14 import org.openstreetmap.josm.actions.JosmAction; … … 14 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 19 import org.openstreetmap.josm.data.osm.Way; 16 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;17 import static org.openstreetmap.josm.tools.I18n.tr;18 20 import org.openstreetmap.josm.tools.Shortcut; 19 21 20 22 /** 21 * 23 * Unselects all nodes 22 24 */ 23 25 public class SelectModWaysAction extends JosmAction { … … 28 30 super(tr("Select last modified ways"), "selmodways", 29 31 tr("Select last modified ways"), 30 Shortcut.registerShortcut("tools:selmodways", tr("Tool: {0}","Select last modified ways"), 31 KeyEvent.VK_Z, 32 Shortcut.registerShortcut("tools:selmodways", tr("Tool: {0}", "Select last modified ways"), 33 KeyEvent.VK_Z, Shortcut.ALT_SHIFT), true); 32 34 putValue("help", ht("/Action/SelectLastModifiedWays")); 33 35 } … … 42 44 43 45 if (Main.main.undoRedo.commands == null) return; 44 int num =Main.main.undoRedo.commands.size();45 if (num ==0) return;46 int k =0,idx;47 if (selection !=null && !selection.isEmpty() && selection.hashCode() == lastHash) {46 int num = Main.main.undoRedo.commands.size(); 47 if (num == 0) return; 48 int k = 0, idx; 49 if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) { 48 50 // we are selecting next command in history if nothing is selected 49 51 idx = Main.main.undoRedo.commands.indexOf(lastCmd); 50 // System.out.println("My previous selection found "+idx);51 52 } else { 52 idx=num; 53 // System.out.println("last history item taken"); 53 idx = num; 54 54 } 55 55 56 56 Set<Way> ways = new HashSet<>(10); 57 57 do { // select next history element 58 if (idx >0) idx--; else idx=num-1;58 if (idx > 0) idx--; else idx = num-1; 59 59 cmd = Main.main.undoRedo.commands.get(idx); 60 60 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 61 61 ways.clear(); 62 for ( 63 if (p instanceof Way && !p.isDeleted()) ways.add((Way)p); 62 for (OsmPrimitive p : pp) { // find all affected ways 63 if (p instanceof Way && !p.isDeleted()) ways.add((Way) p); 64 64 } 65 65 if (!ways.isEmpty() && !ds.getSelected().containsAll(ways)) { … … 68 68 lastHash = ds.getSelected().hashCode(); 69 69 return; 70 70 } 71 71 k++; 72 } while ( k < num ); // try to find previous command if this affects nothing 73 lastCmd=null; lastHash=0; 72 } while (k < num); // try to find previous command if this affects nothing 73 lastCmd = null; 74 lastHash = 0; 74 75 } 75 76 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectWayNodesAction.java
r32333 r32410 1 // License: GPL. Copyright 2010 by Hanno Hecker1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 18 18 /** 19 19 * Select all nodes of a selected way. 20 *21 20 */ 22 23 21 public class SelectWayNodesAction extends JosmAction { 24 22 … … 29 27 */ 30 28 public SelectWayNodesAction() { 31 super(tr("Select Way Nodes"),"selectwaynodes" , tr("Select all nodes of a selected way."), 32 Shortcut.registerShortcut("tools:selectwaynodes", tr("Tool: {0}", tr("Select Way Nodes")), KeyEvent.VK_N, Shortcut.CTRL_SHIFT), true); 29 super(tr("Select Way Nodes"), "selectwaynodes", tr("Select all nodes of a selected way."), 30 Shortcut.registerShortcut("tools:selectwaynodes", tr("Tool: {0}", tr("Select Way Nodes")), 31 KeyEvent.VK_N, Shortcut.CTRL_SHIFT), true); 33 32 putValue("help", ht("/Action/SelectWayNodes")); 34 33 } … … 50 49 } 51 50 selectWayNodes(w); 52 } 53 else if (p instanceof Node) { 51 } else if (p instanceof Node) { 54 52 Node n = (Node) p; 55 53 if (selectedNodes == null) { … … 59 57 } 60 58 } 61 59 62 60 getLayerManager().getEditDataSet().setSelected(selectedNodes); 63 61 selectedNodes = null; … … 65 63 66 64 private void selectWayNodes(Way w) { 67 65 68 66 for (Node n : w.getNodes()) { 69 67 if (selectedNodes == null) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UndoSelectionAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 11 11 import java.util.LinkedList; 12 12 import java.util.Set; 13 13 14 import org.openstreetmap.josm.actions.JosmAction; 14 import org.openstreetmap.josm.data.osm. *;15 15 import org.openstreetmap.josm.data.osm.DataSet; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 17 import org.openstreetmap.josm.tools.Shortcut; 17 18 18 19 /** 19 * 20 * Use selection istory to restore previous selection 20 21 */ 21 22 public class UndoSelectionAction extends JosmAction { 22 23 23 24 public UndoSelectionAction() { 24 25 super(tr("Undo selection"), "undoselection", 25 26 tr("Reselect last added object or selection form history"), 26 Shortcut.registerShortcut("tools:undoselection", tr("Tool: {0}","Undo selection"), 27 KeyEvent.VK_Z, Shortcut.CTRL_SHIFT), true); 27 Shortcut.registerShortcut("tools:undoselection", tr("Tool: {0}", "Undo selection"), 28 KeyEvent.VK_Z, Shortcut.CTRL_SHIFT), true); 28 29 putValue("help", ht("/Action/UndoSelection")); 29 30 } … … 36 37 DataSet ds = getLayerManager().getEditDataSet(); 37 38 LinkedList<Collection<? extends OsmPrimitive>> history = ds.getSelectionHistory(); 38 if (history ==null || history.isEmpty()) return; // empty history39 int num =history.size();40 39 if (history == null || history.isEmpty()) return; // empty history 40 int num = history.size(); 41 41 42 Collection<OsmPrimitive> selection = ds.getSelected(); 42 43 43 if (selection!= null && 44 if (selection != null && selection.hashCode() != myAutomaticSelectionHash) { 44 45 // manual selection or another pluging selection noticed 45 index =history.indexOf(lastSel);46 index = history.indexOf(lastSel); 46 47 // first is selected, next list is previous selection 47 48 } 48 int k =0;49 int k = 0; 49 50 Set<OsmPrimitive> newsel = new HashSet<>(); 50 51 do { 51 if (index+1 <history.size()) index++; else index=0;52 if (index+1 < history.size()) index++; else index = 0; 52 53 Collection<? extends OsmPrimitive> histsel = history.get(index); 53 54 // remove deleted entities from selection … … 55 56 newsel.addAll(histsel); 56 57 newsel.retainAll(ds.allNonDeletedPrimitives()); 57 if (newsel.size() > 0 58 if (newsel.size() > 0) break; 58 59 k++; 59 } while ( k < num);60 } while (k < num); 60 61 61 62 ds.setSelected(newsel); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UnselectNodesAction.java
r32333 r32410 1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 … … 9 9 import java.util.Collection; 10 10 import java.util.Set; 11 11 12 import org.openstreetmap.josm.actions.JosmAction; 12 import org.openstreetmap.josm.data.osm. *;13 13 import org.openstreetmap.josm.data.osm.Node; 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 15 import org.openstreetmap.josm.tools.Shortcut; 15 16 … … 25 26 super(tr("Unselect nodes"), "unsnodes", 26 27 tr("Removes all nodes from selection"), 27 Shortcut.registerShortcut("tools:unsnodes", tr("Tool: {0}","Unselect nodes"), 28 KeyEvent.VK_U, Shortcut.SHIFT), true); 28 Shortcut.registerShortcut("tools:unsnodes", tr("Tool: {0}", "Unselect nodes"), 29 KeyEvent.VK_U, Shortcut.SHIFT), true); 29 30 putValue("help", ht("/Action/UnselectNodes")); 30 31 }
Note:
See TracChangeset
for help on using the changeset viewer.