Changeset 17722 in osm
- Timestamp:
- 2009-09-20T18:00:49+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/Test.java
r17479 r17722 14 14 import org.openstreetmap.josm.data.osm.Way; 15 15 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 16 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 16 18 import org.openstreetmap.josm.tools.GBC; 19 import static org.openstreetmap.josm.tools.I18n.tr; 17 20 18 21 /** … … 53 56 /** Whether the test is run on a partial selection data */ 54 57 protected boolean partialSelection; 58 59 /** the progress monitor to use */ 60 protected ProgressMonitor progressMonitor; 55 61 56 62 /** … … 82 88 83 89 /** 84 * Notification of the start of the test. The tester can initialize the 85 * structures it may need for this test 86 */ 87 public void startTest() 88 { 89 errors = new ArrayList<TestError>(30); 90 * Start the test using a given progress monitor 91 * 92 * @param progressMonitor the progress monitor 93 */ 94 public void startTest(ProgressMonitor progressMonitor) { 95 if (progressMonitor == null) { 96 this.progressMonitor = NullProgressMonitor.INSTANCE; 97 } else { 98 this.progressMonitor = progressMonitor; 99 } 100 this.progressMonitor.beginTask(tr("Running test {0}", name)); 101 errors = new ArrayList<TestError>(30); 90 102 } 91 103 … … 112 124 * actions and destroy the used structures 113 125 */ 114 public void endTest() {} 126 public void endTest() { 127 progressMonitor.finishTask(); 128 progressMonitor = null; 129 } 115 130 116 131 /** … … 122 137 public void visit(Collection<OsmPrimitive> selection) 123 138 { 124 for (OsmPrimitive p : selection)125 {139 progressMonitor.setTicksCount(selection.size()); 140 for (OsmPrimitive p : selection) { 126 141 if( p.isUsable() ) 127 142 p.visit(this); 143 progressMonitor.worked(1); 128 144 } 129 145 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java
r16681 r17722 5 5 import java.awt.event.ActionEvent; 6 6 import java.awt.event.KeyEvent; 7 import java.io.IOException; 7 8 import java.util.ArrayList; 8 9 import java.util.Collection; 9 10 import java.util.List; 11 12 import javax.swing.SwingUtilities; 10 13 11 14 import org.openstreetmap.josm.Main; … … 13 16 import org.openstreetmap.josm.data.osm.DataSet; 14 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 19 import org.openstreetmap.josm.io.OsmTransferException; 15 20 import org.openstreetmap.josm.plugins.validator.util.AgregatePrimitivesVisitor; 16 21 import org.openstreetmap.josm.tools.Shortcut; 22 import org.xml.sax.SAXException; 17 23 18 24 /** … … 84 90 } 85 91 86 List<TestError> errors = new ArrayList<TestError>(200); 87 for (Test test : tests) { 88 test.setPartialSelection(lastSelection != null); 89 test.startTest(); 90 test.visit(selection); 91 test.endTest(); 92 errors.addAll(test.getErrors()); 93 } 94 tests = null; 95 if (Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) { 96 for (TestError error : errors) { 97 List<String> s = new ArrayList<String>(); 98 s.add(error.getIgnoreState()); 99 s.add(error.getIgnoreGroup()); 100 s.add(error.getIgnoreSubGroup()); 101 for (String state : s) { 102 if (state != null && plugin.ignoredErrors.contains(state)) { 103 error.setIgnored(true); 104 } 105 } 106 } 107 } 108 109 plugin.validationDialog.tree.setErrors(errors); 110 plugin.validationDialog.setVisible(true); 111 DataSet.fireSelectionChanged(Main.main.getCurrentDataSet().getSelected()); 92 ValidationTask task = new ValidationTask(tests, selection, lastSelection); 93 Main.worker.submit(task); 112 94 } 113 95 … … 116 98 setEnabled(getEditLayer() != null); 117 99 } 100 101 /** 102 * Asynchronous task for running a collection of tests against a collection 103 * of primitives 104 * 105 */ 106 107 class ValidationTask extends PleaseWaitRunnable { 108 private Collection<Test> tests; 109 private Collection<OsmPrimitive> validatedPrimitmives; 110 private Collection<OsmPrimitive> formerValidatedPrimitives; 111 private boolean canceled; 112 private List<TestError> errors; 113 114 /** 115 * 116 * @param tests the tests to run 117 * @param validatedPrimitives the collection of primitives to validate. 118 * @param formerValidatedPrimitives the last collection of primitives being validates. May be null. 119 */ 120 public ValidationTask(Collection<Test> tests, Collection<OsmPrimitive> validatedPrimitives, Collection<OsmPrimitive> formerValidatedPrimitives) { 121 super(tr("Validating"), false /*don't ignore exceptions */); 122 this.validatedPrimitmives = validatedPrimitives; 123 this.formerValidatedPrimitives = formerValidatedPrimitives; 124 this.tests = tests; 125 } 126 127 @Override 128 protected void cancel() { 129 this.canceled = true; 130 } 131 132 @Override 133 protected void finish() { 134 if (canceled) return; 135 136 // update GUI on Swing EDT 137 // 138 Runnable r = new Runnable() { 139 public void run() { 140 plugin.validationDialog.tree.setErrors(errors); 141 plugin.validationDialog.setVisible(true); 142 DataSet.fireSelectionChanged(Main.main.getCurrentDataSet().getSelected()); 143 } 144 }; 145 if (SwingUtilities.isEventDispatchThread()) { 146 r.run(); 147 } else { 148 SwingUtilities.invokeLater(r); 149 } 150 } 151 152 @Override 153 protected void realRun() throws SAXException, IOException, 154 OsmTransferException { 155 if (tests == null || tests.isEmpty()) return; 156 errors = new ArrayList<TestError>(200); 157 getProgressMonitor().setTicksCount(tests.size() * validatedPrimitmives.size()); 158 int testCounter = 0; 159 for (Test test : tests) { 160 if (canceled) return; 161 testCounter++; 162 getProgressMonitor().setCustomText(tr("Test {0}/{1}: Starting {2}", testCounter, tests.size(),test.name)); 163 test.setPartialSelection(formerValidatedPrimitives != null); 164 test.startTest(getProgressMonitor().createSubTaskMonitor(validatedPrimitmives.size(), false)); 165 test.visit(validatedPrimitmives); 166 test.endTest(); 167 errors.addAll(test.getErrors()); 168 } 169 tests = null; 170 if (Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) { 171 getProgressMonitor().subTask(tr("Updating ignored errors ...")); 172 for (TestError error : errors) { 173 if (canceled) return; 174 List<String> s = new ArrayList<String>(); 175 s.add(error.getIgnoreState()); 176 s.add(error.getIgnoreGroup()); 177 s.add(error.getIgnoreSubGroup()); 178 for (String state : s) { 179 if (state != null && plugin.ignoredErrors.contains(state)) { 180 error.setIgnored(true); 181 } 182 } 183 } 184 } 185 } 186 } 118 187 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateUploadHook.java
r17715 r17722 58 58 test.setBeforeUpload(true); 59 59 test.setPartialSelection(true); 60 test.startTest( );60 test.startTest(null); 61 61 test.visit(selection); 62 62 test.endTest(); -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/Coastlines.java
r17479 r17722 8 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 9 import org.openstreetmap.josm.data.osm.Way; 10 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 10 11 import org.openstreetmap.josm.plugins.validator.Severity; 11 12 import org.openstreetmap.josm.plugins.validator.Test; … … 38 39 39 40 @Override 40 public void startTest( )41 public void startTest(ProgressMonitor monitor) 41 42 { 43 super.startTest(monitor); 42 44 _cellWays = new HashMap<Point2D,List<Way>>(1000); 43 45 _errorWays = new Bag<Way, Way>(); … … 47 49 public void endTest() 48 50 { 51 super.endTest(); 49 52 _cellWays = null; 50 53 _errorWays = null; -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/CrossingWays.java
r17479 r17722 15 15 import org.openstreetmap.josm.data.osm.Way; 16 16 import org.openstreetmap.josm.data.osm.WaySegment; 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 18 import org.openstreetmap.josm.plugins.validator.OSMValidatorPlugin; 18 19 import org.openstreetmap.josm.plugins.validator.Severity; … … 49 50 50 51 @Override 51 public void startTest() 52 { 52 public void startTest(ProgressMonitor monitor) 53 { 54 super.startTest(monitor); 53 55 cellSegments = new HashMap<Point2D,List<ExtendedSegment>>(1000); 54 56 errorSegments = new HashSet<WaySegment>(); … … 59 61 public void endTest() 60 62 { 63 super.endTest(); 61 64 cellSegments = null; 62 65 errorSegments = null; -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/DuplicateNode.java
r17592 r17722 20 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 21 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 22 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 22 23 import org.openstreetmap.josm.plugins.validator.Severity; 23 24 import org.openstreetmap.josm.plugins.validator.Test; … … 59 60 } 60 61 61 62 62 @Override 63 public void startTest( )64 {63 public void startTest(ProgressMonitor monitor) { 64 super.startTest(monitor); 65 65 nodes = new Bag<LatLon, OsmPrimitive>(1000); 66 66 } 67 67 68 @Override 69 public void endTest() 70 { 71 for(List<OsmPrimitive> duplicated : nodes.values() ) 72 { 73 if( duplicated.size() > 1) 74 { 75 boolean sameTags=true; 76 Map<String, String> keys0=duplicated.get(0).getKeys(); 77 keys0.remove("created_by"); 78 for(int i=0;i<duplicated.size();i++) { 79 Map<String, String> keysI=duplicated.get(i).getKeys(); 80 keysI.remove("created_by"); 81 if (!keys0.equals(keysI)) sameTags=false; 68 @Override 69 public void endTest() { 70 for (List<OsmPrimitive> duplicated : nodes.values()) { 71 if (duplicated.size() > 1) { 72 boolean sameTags = true; 73 Map<String, String> keys0 = duplicated.get(0).getKeys(); 74 keys0.remove("created_by"); 75 for (int i = 0; i < duplicated.size(); i++) { 76 Map<String, String> keysI = duplicated.get(i).getKeys(); 77 keysI.remove("created_by"); 78 if (!keys0.equals(keysI)) 79 sameTags = false; 80 } 81 if (!sameTags) { 82 TestError testError = new TestError(this, Severity.WARNING, 83 tr("Nodes at same position"), DUPLICATE_NODE, 84 duplicated); 85 errors.add(testError); 86 } else { 87 TestError testError = new TestError(this, Severity.ERROR, 88 tr("Duplicated nodes"), DUPLICATE_NODE, duplicated); 89 errors.add(testError); 90 } 91 } 82 92 } 83 if (!sameTags) { 84 TestError testError = new TestError(this, Severity.WARNING, tr("Nodes at same position"), DUPLICATE_NODE, duplicated); 85 errors.add( testError ); 86 } else { 87 TestError testError = new TestError(this, Severity.ERROR, tr("Duplicated nodes"), DUPLICATE_NODE, duplicated); 88 errors.add( testError ); 89 } 90 } 91 } 92 nodes = null; 93 } 93 super.endTest(); 94 nodes = null; 95 } 94 96 95 97 @Override -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/DuplicateWay.java
r17479 r17722 17 17 import org.openstreetmap.josm.data.osm.Way; 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 19 20 import org.openstreetmap.josm.plugins.validator.Severity; 20 21 import org.openstreetmap.josm.plugins.validator.Test; … … 62 63 63 64 @Override 64 public void startTest( )65 public void startTest(ProgressMonitor monitor) 65 66 { 67 super.startTest(monitor); 66 68 ways = new Bag<WayPair, OsmPrimitive>(1000); 67 69 } … … 70 72 public void endTest() 71 73 { 74 super.endTest(); 72 75 for(List<OsmPrimitive> duplicated : ways.values() ) 73 76 { -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/NodesWithSameName.java
r17479 r17722 8 8 import java.util.ArrayList; 9 9 10 10 11 import org.openstreetmap.josm.data.osm.Node; 12 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 11 13 import org.openstreetmap.josm.plugins.validator.Severity; 12 14 import org.openstreetmap.josm.plugins.validator.Test; … … 23 25 } 24 26 25 @Override public void startTest() { 27 @Override public void startTest(ProgressMonitor monitor) { 28 super.startTest(monitor); 26 29 namesToNodes = new HashMap<String, List<Node>>(); 27 30 } … … 48 51 } 49 52 } 50 53 super.endTest(); 51 54 namesToNodes = null; 52 55 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/OverlappingWays.java
r17351 r17722 13 13 import org.openstreetmap.josm.data.osm.Way; 14 14 import org.openstreetmap.josm.data.osm.WaySegment; 15 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 15 16 import org.openstreetmap.josm.plugins.validator.Severity; 16 17 import org.openstreetmap.josm.plugins.validator.Test; … … 48 49 49 50 @Override 50 public void startTest( )51 public void startTest(ProgressMonitor monitor) 51 52 { 53 super.startTest(monitor); 52 54 nodePairs = new Bag<Pair<Node,Node>, WaySegment>(1000); 53 55 } … … 149 151 } 150 152 } 153 super.endTest(); 151 154 nodePairs = null; 152 155 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/SimilarNamedWays.java
r17479 r17722 6 6 import java.util.*; 7 7 8 8 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 10 import org.openstreetmap.josm.data.osm.Way; 11 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 10 12 import org.openstreetmap.josm.plugins.validator.Severity; 11 13 import org.openstreetmap.josm.plugins.validator.Test; … … 39 41 40 42 @Override 41 public void startTest( )43 public void startTest(ProgressMonitor monitor) 42 44 { 45 super.startTest(monitor); 43 46 cellWays = new HashMap<Point2D,List<Way>>(1000); 44 47 errorWays = new Bag<Way, Way>(); … … 50 53 cellWays = null; 51 54 errorWays = null; 55 super.endTest(); 52 56 } 53 57 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java
r17351 r17722 45 45 import org.openstreetmap.josm.data.osm.Way; 46 46 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 47 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 47 48 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 48 49 import org.openstreetmap.josm.io.MirroredInputStream; … … 553 554 554 555 @Override 555 public void startTest() 556 { 556 public void startTest(ProgressMonitor monitor) 557 { 558 super.startTest(monitor); 557 559 checkKeys = Main.pref.getBoolean(PREF_CHECK_KEYS, true); 558 560 if( isBeforeUpload ) -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java
r17479 r17722 12 12 import org.openstreetmap.josm.data.osm.OsmUtils; 13 13 import org.openstreetmap.josm.data.osm.Way; 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 14 15 import org.openstreetmap.josm.plugins.validator.Severity; 15 16 import org.openstreetmap.josm.plugins.validator.Test; … … 34 35 35 36 @Override 36 public void startTest() { 37 public void startTest(ProgressMonitor monitor) { 38 super.startTest(monitor); 37 39 _errorWays = new Bag<Way, Way>(); 38 40 } … … 41 43 public void endTest() { 42 44 _errorWays = null; 45 super.endTest(); 43 46 } 44 47 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnconnectedWays.java
r17479 r17722 15 15 import org.openstreetmap.josm.data.osm.OsmUtils; 16 16 import org.openstreetmap.josm.data.osm.Way; 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 18 import org.openstreetmap.josm.plugins.validator.PreferenceEditor; 18 19 import org.openstreetmap.josm.plugins.validator.Severity; … … 48 49 49 50 @Override 50 public void startTest() 51 { 51 public void startTest(ProgressMonitor monitor) 52 { 53 super.startTest(monitor); 52 54 ways = new HashSet<MyWaySegment>(); 53 55 endnodes = new HashSet<Node>(); … … 153 155 ways = null; 154 156 endnodes = null; 157 super.endTest(); 155 158 } 156 159 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UntaggedNode.java
r17479 r17722 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 14 import org.openstreetmap.josm.data.osm.Way; 15 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 15 16 import org.openstreetmap.josm.plugins.validator.Severity; 16 17 import org.openstreetmap.josm.plugins.validator.Test; … … 39 40 40 41 @Override 41 public void startTest( )42 public void startTest(ProgressMonitor monitor) 42 43 { 44 super.startTest(monitor); 43 45 emptyNodes = new HashSet<Node>(100); 44 46 } … … 91 93 } 92 94 emptyNodes = null; 95 super.endTest(); 93 96 } 94 97 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UntaggedWay.java
r17540 r17722 14 14 import org.openstreetmap.josm.data.osm.RelationMember; 15 15 import org.openstreetmap.josm.data.osm.Way; 16 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 16 17 import org.openstreetmap.josm.plugins.validator.Severity; 17 18 import org.openstreetmap.josm.plugins.validator.Test; … … 112 113 113 114 @Override 114 public void startTest( )115 public void startTest(ProgressMonitor monitor) 115 116 { 117 super.startTest(monitor); 116 118 multipolygonways = new LinkedList<Way>(); 117 119 for (final Relation r : Main.main.getCurrentDataSet().relations) … … 133 135 { 134 136 multipolygonways = null; 137 super.endTest(); 135 138 } 136 139 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/WronglyOrderedWays.java
r17479 r17722 8 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 9 import org.openstreetmap.josm.data.osm.Way; 10 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 10 11 import org.openstreetmap.josm.plugins.validator.Severity; 11 12 import org.openstreetmap.josm.plugins.validator.Test; … … 36 37 37 38 @Override 38 public void startTest( )39 public void startTest(ProgressMonitor monitor) 39 40 { 41 super.startTest(monitor); 40 42 _errorWays = new Bag<Way, Way>(); 41 43 } … … 45 47 { 46 48 _errorWays = null; 49 super.endTest(); 47 50 } 48 51
Note:
See TracChangeset
for help on using the changeset viewer.