Changeset 17585 in osm
- Timestamp:
- 2009-09-12T06:29:25+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/validator
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/build.xml
r17540 r17585 26 26 <attribute name="Plugin-Description" value="An OSM data validator. It checks for problems in data, and provides fixes for the common ones. Spellcheck integrated for tag names."/> 27 27 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/Validator"/> 28 <attribute name="Plugin-Mainversion" value="20 82"/>28 <attribute name="Plugin-Mainversion" value="2095"/> 29 29 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 30 30 </manifest> -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java
r17479 r17585 11 11 import java.awt.event.MouseAdapter; 12 12 import java.awt.event.MouseEvent; 13 import java.io.IOException; 14 import java.lang.reflect.InvocationTargetException; 15 import java.util.ArrayList; 13 16 import java.util.Collection; 14 17 import java.util.Enumeration; 15 18 import java.util.HashSet; 19 import java.util.LinkedList; 16 20 import java.util.Set; 17 21 … … 21 25 import javax.swing.JPopupMenu; 22 26 import javax.swing.JScrollPane; 27 import javax.swing.SwingUtilities; 23 28 import javax.swing.event.TreeSelectionEvent; 24 29 import javax.swing.event.TreeSelectionListener; … … 33 38 import org.openstreetmap.josm.data.osm.WaySegment; 34 39 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 40 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 35 41 import org.openstreetmap.josm.gui.SideButton; 36 42 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 43 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 44 import org.openstreetmap.josm.io.OsmTransferException; 45 import org.openstreetmap.josm.plugins.validator.tests.DuplicateNode; 37 46 import org.openstreetmap.josm.tools.Shortcut; 47 import org.xml.sax.SAXException; 38 48 39 49 /** … … 133 143 134 144 Set<DefaultMutableTreeNode> processedNodes = new HashSet<DefaultMutableTreeNode>(); 145 146 DuplicateNode.clearBackreferences(); 147 LinkedList<TestError> errorsToFix = new LinkedList<TestError>(); 135 148 for (TreePath path : selectionPaths) { 136 149 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); … … 147 160 Object nodeInfo = childNode.getUserObject(); 148 161 if (nodeInfo instanceof TestError) { 149 TestError error = (TestError) nodeInfo; 150 Command fixCommand = error.getFix(); 151 if (fixCommand != null) { 152 Main.main.undoRedo.add(fixCommand); 153 error.setIgnored(true); 154 } 162 errorsToFix.add((TestError)nodeInfo); 155 163 } 156 164 } 157 165 } 158 159 Main.map.repaint(); 160 tree.resetErrors(); 161 DataSet.fireSelectionChanged(Main.main.getCurrentDataSet().getSelected()); 166 167 // run fix task asynchronously 168 // 169 FixTask fixTask = new FixTask(errorsToFix); 170 Main.worker.submit(fixTask); 162 171 } 163 172 … … 436 445 tree.setFilter(filter); 437 446 } 447 448 /** 449 * Task for fixing a collection of {@see TestError}s. Can be run asynchronously. 450 * 451 * 452 */ 453 class FixTask extends PleaseWaitRunnable { 454 private Collection<TestError> testErrors; 455 private boolean canceled; 456 private LinkedList<Command> fixCommands; 457 458 459 public FixTask(Collection<TestError> testErrors) { 460 super(tr("Fixing errors ..."), false /* don't ignore exceptions */); 461 this.testErrors = testErrors == null ? new ArrayList<TestError> (): testErrors; 462 fixCommands = new LinkedList<Command>(); 463 } 464 465 @Override 466 protected void cancel() { 467 this.canceled = true; 468 } 469 470 @Override 471 protected void finish() { 472 // do nothing 473 } 474 475 @Override 476 protected void realRun() throws SAXException, IOException, 477 OsmTransferException { 478 ProgressMonitor monitor = getProgressMonitor(); 479 try { 480 monitor.setTicksCount(testErrors.size()); 481 int i=0; 482 for (TestError error: testErrors) { 483 i++; 484 monitor.subTask(tr("Fixing ({0}/{1}): ''{2}''", i, testErrors.size(),error.getMessage())); 485 if (this.canceled) 486 return; 487 final Command fixCommand = error.getFix(); 488 if (fixCommand != null) { 489 fixCommands.add(fixCommand); 490 SwingUtilities.invokeAndWait( 491 new Runnable() { 492 public void run() { 493 Main.main.undoRedo.add(fixCommand); 494 } 495 } 496 ); 497 error.setIgnored(true); 498 } 499 monitor.worked(1); 500 } 501 monitor.subTask(tr("Updating map ...")); 502 SwingUtilities.invokeAndWait(new Runnable() { 503 public void run() { 504 Main.map.repaint(); 505 tree.resetErrors(); 506 DataSet.fireSelectionChanged(Main.main.getCurrentDataSet().getSelected()); 507 } 508 }); 509 } catch(InterruptedException e) { 510 // FIXME: signature of realRun should have a generic checked exception we 511 // could throw here 512 throw new RuntimeException(e); 513 } catch(InvocationTargetException e) { 514 throw new RuntimeException(e); 515 } finally { 516 monitor.finishTask(); 517 } 518 } 519 } 438 520 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/DuplicateNode.java
r17481 r17585 16 16 import org.openstreetmap.josm.command.Command; 17 17 import org.openstreetmap.josm.data.coor.LatLon; 18 import org.openstreetmap.josm.data.osm.BackreferencedDataSet; 18 19 import org.openstreetmap.josm.data.osm.Node; 19 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 28 29 * @author frsantos 29 30 */ 30 public class DuplicateNode extends Test 31 { 31 public class DuplicateNode extends Test{ 32 33 private static BackreferencedDataSet backreferences; 34 35 public static BackreferencedDataSet getBackreferenceDataSet() { 36 if (backreferences == null) { 37 backreferences = new BackreferencedDataSet(Main.main.getEditLayer().data); 38 backreferences.build(); 39 } 40 return backreferences; 41 } 42 43 public static void clearBackreferences() { 44 backreferences = null; 45 } 46 32 47 protected static int DUPLICATE_NODE = 1; 33 48 … … 92 107 public Command fixError(TestError testError) 93 108 { 94 Collection<? extends OsmPrimitive> sel = testError.getPrimitives(); 95 LinkedList<Node> nodes = new LinkedList<Node>(); 109 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(testError.getPrimitives()); 110 LinkedList<Node> nodes = new LinkedList<Node>(OsmPrimitive.getFilteredList(sel, Node.class)); 111 MergeNodesAction mergeAction = new MergeNodesAction(); 112 Node target = mergeAction.selectTargetNode(nodes); 113 if(checkAndConfirmOutlyingDeletes(nodes)) 114 return mergeAction.mergeNodes(Main.main.getEditLayer(),getBackreferenceDataSet(), nodes, target); 96 115 97 for (OsmPrimitive osm : sel) 98 if (osm instanceof Node) 99 nodes.add((Node)osm); 100 101 if( nodes.size() < 2 ) 102 return null; 103 104 Node target = null; 105 // select the target node in the same way as in the core action MergeNodesAction, rev.1084 106 for (Node n: nodes) { 107 if (n.getId() > 0) { 108 target = n; 109 break; 110 } 111 } 112 if (target == null) 113 target = nodes.iterator().next(); 114 115 if(checkAndConfirmOutlyingDeletes(nodes)) 116 new MergeNodesAction().mergeNodes(nodes, target); 117 118 return null; // undoRedo handling done in mergeNodes 116 return null;// undoRedo handling done in mergeNodes 119 117 } 120 118
Note:
See TracChangeset
for help on using the changeset viewer.