Changeset 10663 in osm for applications
- Timestamp:
- 2008-09-13T17:23:27+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorLayer.java
r10529 r10663 29 29 * @author frsantos 30 30 */ 31 public class ErrorLayer extends Layer implements LayerChangeListener 32 { 33 private OSMValidatorPlugin plugin; 31 public class ErrorLayer extends Layer implements LayerChangeListener { 32 private OSMValidatorPlugin plugin; 34 33 35 36 37 38 Layer.listeners.add(this); 39 34 public ErrorLayer(OSMValidatorPlugin plugin) { 35 super(tr("Validation errors")); 36 this.plugin = plugin; 37 Layer.listeners.add(this); 38 } 40 39 41 /** 42 * Return a static icon. 43 */ 44 @Override public Icon getIcon() { 45 return ImageProvider.get("layer", "validator"); 46 } 40 /** 41 * Return a static icon. 42 */ 43 @Override 44 public Icon getIcon() { 45 return ImageProvider.get("layer", "validator"); 46 } 47 47 48 /** 49 * Draw all primitives in this layer but do not draw modified ones (they 50 * are drawn by the edit layer). 51 * Draw nodes last to overlap the ways they belong to. 52 */ 53 @SuppressWarnings("unchecked") 54 @Override 55 public void paint(final Graphics g, final MapView mv) 56 { 57 DefaultMutableTreeNode root = plugin.validationDialog.tree.getRoot(); 58 if( root == null || root.getChildCount() == 0) 59 return; 60 61 DefaultMutableTreeNode severity = (DefaultMutableTreeNode)root.getLastChild(); 62 while( severity != null ) 63 { 64 Enumeration<DefaultMutableTreeNode> errorMessages = severity.breadthFirstEnumeration(); 65 while(errorMessages.hasMoreElements()) 66 { 67 Object tn = errorMessages.nextElement().getUserObject(); 68 if(tn instanceof TestError) 69 ((TestError)tn).paint(g, mv); 70 } 71 72 // Severities in inverse order 73 severity = severity.getPreviousSibling(); 74 } 75 } 48 /** 49 * Draw all primitives in this layer but do not draw modified ones (they 50 * are drawn by the edit layer). 51 * Draw nodes last to overlap the ways they belong to. 52 */ 53 @SuppressWarnings("unchecked") 54 @Override 55 public void paint(final Graphics g, final MapView mv) { 56 DefaultMutableTreeNode root = plugin.validationDialog.tree.getRoot(); 57 if (root == null || root.getChildCount() == 0) 58 return; 76 59 77 @Override 78 public String getToolTipText() 79 { 80 Bag<Severity, TestError> errorTree = new Bag<Severity, TestError>(); 81 List<TestError> errors = plugin.validationDialog.tree.getErrors(); 82 for(TestError e : errors) 83 { 84 errorTree.add(e.getSeverity(), e); 85 } 86 87 StringBuilder b = new StringBuilder(); 88 for(Severity s : Severity.values()) 89 { 90 if( errorTree.containsKey(s) ) 91 b.append(tr(s.toString())).append(": ").append(errorTree.get(s).size()).append("<br>"); 92 } 93 94 if( b.length() == 0 ) 95 return "<html>"+tr("No validation errors") + "</html>"; 96 else 97 return "<html>" + tr("Validation errors") + ":<br>" + b + "</html>"; 98 } 60 DefaultMutableTreeNode severity = (DefaultMutableTreeNode) root.getLastChild(); 61 while (severity != null) { 62 Enumeration<DefaultMutableTreeNode> errorMessages = severity.breadthFirstEnumeration(); 63 while (errorMessages.hasMoreElements()) { 64 Object tn = errorMessages.nextElement().getUserObject(); 65 if (tn instanceof TestError) 66 ((TestError) tn).paint(g, mv); 67 } 99 68 100 @Override public void mergeFrom(Layer from) {} 69 // Severities in inverse order 70 severity = severity.getPreviousSibling(); 71 } 72 } 101 73 102 @Override public boolean isMergable(Layer other) { 103 return false; 104 } 74 @Override 75 public String getToolTipText() { 76 Bag<Severity, TestError> errorTree = new Bag<Severity, TestError>(); 77 List<TestError> errors = plugin.validationDialog.tree.getErrors(); 78 for (TestError e : errors) { 79 errorTree.add(e.getSeverity(), e); 80 } 105 81 106 @Override public void visitBoundingBox(BoundingXYVisitor v) {} 82 StringBuilder b = new StringBuilder(); 83 for (Severity s : Severity.values()) { 84 if (errorTree.containsKey(s)) 85 b.append(tr(s.toString())).append(": ").append(errorTree.get(s).size()).append("<br>"); 86 } 107 87 108 @Override public Object getInfoComponent() 109 { 110 return getToolTipText(); 111 } 88 if (b.length() == 0) 89 return "<html>" + tr("No validation errors") + "</html>"; 90 else 91 return "<html>" + tr("Validation errors") + ":<br>" + b + "</html>"; 92 } 112 93 113 @Override public Component[] getMenuEntries() 114 { 115 return new Component[]{ 116 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 117 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 118 new JSeparator(), 119 new JMenuItem(new RenameLayerAction(null, this)), 120 new JSeparator(), 121 new JMenuItem(new LayerListPopup.InfoAction(this))}; 122 } 94 @Override 95 public void mergeFrom(Layer from) { 96 } 123 97 124 @Override public void destroy() { } 98 @Override 99 public boolean isMergable(Layer other) { 100 return false; 101 } 125 102 126 public void activeLayerChange(Layer oldLayer, Layer newLayer) { } 103 @Override 104 public void visitBoundingBox(BoundingXYVisitor v) { 105 } 127 106 128 public void layerAdded(Layer newLayer) { } 107 @Override 108 public Object getInfoComponent() { 109 return getToolTipText(); 110 } 129 111 130 /** 131 * If layer is the OSM Data layer, remove all errors 132 */ 133 public void layerRemoved(Layer oldLayer) 134 { 135 if(oldLayer == Main.map.mapView.editLayer ) 136 { 137 Main.map.mapView.removeLayer(this); 138 } 139 } 112 @Override 113 public Component[] getMenuEntries() { 114 return new Component[] { new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 115 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), new JSeparator(), 116 new JMenuItem(new RenameLayerAction(null, this)), new JSeparator(), 117 new JMenuItem(new LayerListPopup.InfoAction(this)) }; 118 } 119 120 @Override 121 public void destroy() { 122 } 123 124 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 125 } 126 127 public void layerAdded(Layer newLayer) { 128 } 129 130 /** 131 * If layer is the OSM Data layer, remove all errors 132 */ 133 public void layerRemoved(Layer oldLayer) { 134 if (oldLayer == Main.map.mapView.editLayer) { 135 Main.map.mapView.removeLayer(this); 136 } else if (oldLayer == this) { 137 OSMValidatorPlugin.errorLayer = null; 138 } 139 } 140 140 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
r10519 r10663 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.lang.reflect.InvocationTargetException;6 5 import java.io.BufferedReader; 7 6 import java.io.FileNotFoundException; … … 10 9 import java.io.IOException; 11 10 import java.io.PrintWriter; 11 import java.lang.reflect.InvocationTargetException; 12 12 import java.util.ArrayList; 13 13 import java.util.Collection; 14 import java.util.HashMap; 14 15 import java.util.Iterator; 15 16 import java.util.LinkedList; 16 17 import java.util.List; 17 import java.util.HashMap;18 18 import java.util.Map; 19 19 import java.util.TreeSet; … … 32 32 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 33 33 import org.openstreetmap.josm.plugins.Plugin; 34 import org.openstreetmap.josm.plugins.validator.tests.*; 34 import org.openstreetmap.josm.plugins.validator.tests.Coastlines; 35 import org.openstreetmap.josm.plugins.validator.tests.CrossingWays; 36 import org.openstreetmap.josm.plugins.validator.tests.DuplicateNode; 37 import org.openstreetmap.josm.plugins.validator.tests.DuplicatedWayNodes; 38 import org.openstreetmap.josm.plugins.validator.tests.NodesWithSameName; 39 import org.openstreetmap.josm.plugins.validator.tests.OverlappingWays; 40 import org.openstreetmap.josm.plugins.validator.tests.SelfIntersectingWay; 41 import org.openstreetmap.josm.plugins.validator.tests.SimilarNamedWays; 42 import org.openstreetmap.josm.plugins.validator.tests.TagChecker; 43 import org.openstreetmap.josm.plugins.validator.tests.UnclosedWays; 44 import org.openstreetmap.josm.plugins.validator.tests.UnconnectedWays; 45 import org.openstreetmap.josm.plugins.validator.tests.UntaggedNode; 46 import org.openstreetmap.josm.plugins.validator.tests.UntaggedWay; 47 import org.openstreetmap.josm.plugins.validator.tests.WronglyOrderedWays; 35 48 import org.openstreetmap.josm.plugins.validator.util.Util; 36 49 … … 41 54 * @author Francisco R. Santos <frsantos@gmail.com> 42 55 */ 43 public class OSMValidatorPlugin extends Plugin implements LayerChangeListener 44 { 45 /** The validate action */ 46 ValidateAction validateAction = new ValidateAction(this); 47 48 /** The validation dialog */ 49 ValidatorDialog validationDialog; 50 51 /** The list of errors per layer*/ 52 Map<Layer, List<TestError>> layerErrors = new HashMap<Layer, List<TestError>>(); 53 54 public Collection<String> ignoredErrors = new TreeSet<String>(); 55 56 /** 57 * All available tests 58 * TODO: is there any way to find out automagically all available tests? 59 */ 60 public static Class[] allAvailableTests = new Class[] 61 { 62 DuplicateNode.class, // ID 1 .. 99 63 OverlappingWays.class, // ID 101 .. 199 64 UntaggedNode.class, // ID 201 .. 299 65 UntaggedWay.class, // ID 301 .. 399 66 SelfIntersectingWay.class, // ID 401 .. 499 67 DuplicatedWayNodes.class, // ID 501 .. 599 68 CrossingWays.class, // ID 601 .. 699 69 SimilarNamedWays.class, // ID 701 .. 799 70 NodesWithSameName.class, // ID 801 .. 899 71 Coastlines.class, // ID 901 .. 999 72 WronglyOrderedWays.class, // ID 1001 .. 1099 73 UnclosedWays.class, // ID 1101 .. 1199 74 TagChecker.class, // ID 1201 .. 1299 75 UnconnectedWays.class, // ID 1301 .. 1399 76 }; 77 78 /** 79 * Creates the plugin, and starts the HTTP server 80 */ 81 public OSMValidatorPlugin() 82 { 83 initializeTests( getTests() ); 84 loadIgnoredErrors(); 85 } 86 87 private void loadIgnoredErrors() { 88 ignoredErrors.clear(); 89 if(Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) 90 { 91 try { 92 final BufferedReader in = new BufferedReader(new FileReader(Util.getPluginDir() + "ignorederrors")); 93 for (String line = in.readLine(); line != null; line = in.readLine()) { 94 ignoredErrors.add(line); 95 } 96 } 97 catch (final FileNotFoundException e) {} 98 catch (final IOException e) { 99 e.printStackTrace(); 100 } 101 } 102 } 103 104 public void saveIgnoredErrors() { 105 try { 106 final PrintWriter out = new PrintWriter(new FileWriter(Util.getPluginDir() + "ignorederrors"), false); 107 for (String e : ignoredErrors) 108 out.println(e); 109 out.close(); 110 } catch (final IOException e) { 111 e.printStackTrace(); 112 } 113 } 114 115 @Override 116 public PreferenceSetting getPreferenceSetting() 117 { 118 return new PreferenceEditor(this); 119 } 120 121 @Override 122 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) 123 { 124 if (newFrame != null) 125 { 126 validationDialog = new ValidatorDialog(this); 127 newFrame.addToggleDialog(validationDialog); 128 if(Main.pref.getBoolean(PreferenceEditor.PREF_LAYER, true)) 129 Main.main.addLayer(new ErrorLayer(this)); 130 if( Main.pref.hasKey(PreferenceEditor.PREF_DEBUG + ".grid") ) 131 Main.main.addLayer(new GridLayer(tr("Grid"))); 132 Layer.listeners.add(this); 133 } 134 else 135 Layer.listeners.remove(this); 136 137 LinkedList<UploadHook> hooks = ((UploadAction)Main.main.menu.upload).uploadHooks; 138 Iterator<UploadHook> hooksIt = hooks.iterator(); 139 while( hooksIt.hasNext() ) 140 { 141 if( hooksIt.next() instanceof ValidateUploadHook ) 142 { 143 if( newFrame == null ) 144 hooksIt.remove(); 145 break; 146 } 147 } 148 if( newFrame != null ) 149 hooks.add( 0, new ValidateUploadHook(this) ); 150 } 151 152 /** Gets a map from simple names to all tests. */ 153 public static Map<String, Test> getAllTestsMap() { 154 Map<String, Test> tests = new HashMap<String, Test>(); 155 for(Class<Test> testClass : getAllAvailableTests() ) 156 { 157 try { 158 Test test = testClass.newInstance(); 159 tests.put(testClass.getSimpleName(), test); 160 } 161 catch( Exception e) 162 { 163 e.printStackTrace(); 164 continue; 165 } 166 } 167 applyPrefs(tests, false); 168 applyPrefs(tests, true); 169 return tests; 170 } 171 172 private static void applyPrefs(Map<String, Test> tests, boolean beforeUpload) { 173 Pattern regexp = Pattern.compile("(\\w+)=(true|false),?"); 174 Matcher m = regexp.matcher(Main.pref.get(beforeUpload 175 ? PreferenceEditor.PREF_TESTS_BEFORE_UPLOAD 176 : PreferenceEditor.PREF_TESTS)); 177 int pos = 0; 178 while( m.find(pos) ) 179 { 180 String testName = m.group(1); 181 Test test = tests.get(testName); 182 if( test != null ) 183 { 184 boolean enabled = Boolean.valueOf(m.group(2)); 185 if (beforeUpload) { 186 test.testBeforeUpload = enabled; 187 } else { 188 test.enabled = enabled; 189 } 190 } 191 pos = m.end(); 192 } 193 } 194 195 public static Collection<Test> getTests() { 196 return getAllTestsMap().values(); 197 } 198 199 public static Collection<Test> getEnabledTests(boolean beforeUpload) { 200 Collection<Test> enabledTests = getTests(); 201 for (Test t : new ArrayList<Test>(enabledTests)) { 202 if (beforeUpload ? t.testBeforeUpload : t.enabled) continue; 203 enabledTests.remove(t); 204 } 205 return enabledTests; 206 } 207 208 /** 209 * Gets the list of all available test classes 210 * 211 * @return An array of the test classes 212 */ 213 public static Class[] getAllAvailableTests() 214 { 215 return allAvailableTests; 216 } 217 218 /** 219 * Initializes all tests 220 * @param allTests The tests to initialize 221 */ 222 public void initializeTests(Collection<Test> allTests) 223 { 224 for( Test test : allTests ) 225 { 226 try 227 { 228 if( test.enabled ) 229 { 230 test.getClass().getMethod("initialize", new Class[] 231 { OSMValidatorPlugin.class} ).invoke(null, new Object[] {this}); 232 } 233 } 234 catch(InvocationTargetException ite) 235 { 236 ite.getCause().printStackTrace(); 237 JOptionPane.showMessageDialog(null, tr("Error initializing test {0}:\n {1}", 238 test.getClass().getSimpleName(), ite.getCause().getMessage())); 239 } 240 catch(Exception e) 241 { 242 e.printStackTrace(); 243 JOptionPane.showMessageDialog(null, tr("Error initializing test {0}:\n {1}", 244 test.getClass().getSimpleName(), e)); 245 } 246 } 247 } 248 249 public void activeLayerChange(Layer oldLayer, Layer newLayer) 250 { 251 if( newLayer instanceof OsmDataLayer ) 252 { 253 List<TestError> errors = layerErrors.get(newLayer); 254 validationDialog.tree.setErrorList(errors); 255 Main.map.repaint(); 256 } 257 } 258 259 public void layerAdded(Layer newLayer) 260 { 261 if( newLayer instanceof OsmDataLayer ) 262 { 263 layerErrors.put(newLayer, new ArrayList<TestError>() ); 264 } 265 } 266 267 public void layerRemoved(Layer oldLayer) 268 { 269 layerErrors.remove(oldLayer); 270 } 56 public class OSMValidatorPlugin extends Plugin implements LayerChangeListener { 57 58 protected static OSMValidatorPlugin plugin; 59 60 protected static ErrorLayer errorLayer = null; 61 62 /** The validate action */ 63 ValidateAction validateAction = new ValidateAction(this); 64 65 /** The validation dialog */ 66 ValidatorDialog validationDialog; 67 68 /** The list of errors per layer*/ 69 Map<Layer, List<TestError>> layerErrors = new HashMap<Layer, List<TestError>>(); 70 71 public Collection<String> ignoredErrors = new TreeSet<String>(); 72 73 /** 74 * All available tests 75 * TODO: is there any way to find out automagically all available tests? 76 */ 77 @SuppressWarnings("unchecked") 78 public static Class<Test>[] allAvailableTests = new Class[] { DuplicateNode.class, // ID 1 .. 99 79 OverlappingWays.class, // ID 101 .. 199 80 UntaggedNode.class, // ID 201 .. 299 81 UntaggedWay.class, // ID 301 .. 399 82 SelfIntersectingWay.class, // ID 401 .. 499 83 DuplicatedWayNodes.class, // ID 501 .. 599 84 CrossingWays.class, // ID 601 .. 699 85 SimilarNamedWays.class, // ID 701 .. 799 86 NodesWithSameName.class, // ID 801 .. 899 87 Coastlines.class, // ID 901 .. 999 88 WronglyOrderedWays.class, // ID 1001 .. 1099 89 UnclosedWays.class, // ID 1101 .. 1199 90 TagChecker.class, // ID 1201 .. 1299 91 UnconnectedWays.class, // ID 1301 .. 1399 92 }; 93 94 /** 95 * Creates the plugin 96 */ 97 public OSMValidatorPlugin() { 98 plugin = this; 99 initializeTests(getTests()); 100 loadIgnoredErrors(); 101 } 102 103 private void loadIgnoredErrors() { 104 ignoredErrors.clear(); 105 if (Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) { 106 try { 107 final BufferedReader in = new BufferedReader(new FileReader(Util.getPluginDir() + "ignorederrors")); 108 for (String line = in.readLine(); line != null; line = in.readLine()) { 109 ignoredErrors.add(line); 110 } 111 } catch (final FileNotFoundException e) { 112 } catch (final IOException e) { 113 e.printStackTrace(); 114 } 115 } 116 } 117 118 public void saveIgnoredErrors() { 119 try { 120 final PrintWriter out = new PrintWriter(new FileWriter(Util.getPluginDir() + "ignorederrors"), false); 121 for (String e : ignoredErrors) 122 out.println(e); 123 out.close(); 124 } catch (final IOException e) { 125 e.printStackTrace(); 126 } 127 } 128 129 @Override 130 public PreferenceSetting getPreferenceSetting() { 131 return new PreferenceEditor(this); 132 } 133 134 @Override 135 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 136 if (newFrame != null) { 137 validationDialog = new ValidatorDialog(this); 138 newFrame.addToggleDialog(validationDialog); 139 initializeErrorLayer(); 140 if (Main.pref.hasKey(PreferenceEditor.PREF_DEBUG + ".grid")) 141 Main.main.addLayer(new GridLayer(tr("Grid"))); 142 Layer.listeners.add(this); 143 } else 144 Layer.listeners.remove(this); 145 146 LinkedList<UploadHook> hooks = ((UploadAction) Main.main.menu.upload).uploadHooks; 147 Iterator<UploadHook> hooksIt = hooks.iterator(); 148 while (hooksIt.hasNext()) { 149 if (hooksIt.next() instanceof ValidateUploadHook) { 150 if (newFrame == null) 151 hooksIt.remove(); 152 break; 153 } 154 } 155 if (newFrame != null) 156 hooks.add(0, new ValidateUploadHook(this)); 157 } 158 159 public void initializeErrorLayer() { 160 if (!Main.pref.getBoolean(PreferenceEditor.PREF_LAYER, true)) 161 return; 162 if (errorLayer == null) { 163 errorLayer = new ErrorLayer(this); 164 Main.main.addLayer(errorLayer); 165 } 166 } 167 168 /** Gets a map from simple names to all tests. */ 169 public static Map<String, Test> getAllTestsMap() { 170 Map<String, Test> tests = new HashMap<String, Test>(); 171 for (Class<Test> testClass : getAllAvailableTests()) { 172 try { 173 Test test = testClass.newInstance(); 174 tests.put(testClass.getSimpleName(), test); 175 } catch (Exception e) { 176 e.printStackTrace(); 177 continue; 178 } 179 } 180 applyPrefs(tests, false); 181 applyPrefs(tests, true); 182 return tests; 183 } 184 185 private static void applyPrefs(Map<String, Test> tests, boolean beforeUpload) { 186 Pattern regexp = Pattern.compile("(\\w+)=(true|false),?"); 187 Matcher m = regexp.matcher(Main.pref.get(beforeUpload ? PreferenceEditor.PREF_TESTS_BEFORE_UPLOAD 188 : PreferenceEditor.PREF_TESTS)); 189 int pos = 0; 190 while (m.find(pos)) { 191 String testName = m.group(1); 192 Test test = tests.get(testName); 193 if (test != null) { 194 boolean enabled = Boolean.valueOf(m.group(2)); 195 if (beforeUpload) { 196 test.testBeforeUpload = enabled; 197 } else { 198 test.enabled = enabled; 199 } 200 } 201 pos = m.end(); 202 } 203 } 204 205 public static Collection<Test> getTests() { 206 return getAllTestsMap().values(); 207 } 208 209 public static Collection<Test> getEnabledTests(boolean beforeUpload) { 210 Collection<Test> enabledTests = getTests(); 211 for (Test t : new ArrayList<Test>(enabledTests)) { 212 if (beforeUpload ? t.testBeforeUpload : t.enabled) 213 continue; 214 enabledTests.remove(t); 215 } 216 return enabledTests; 217 } 218 219 /** 220 * Gets the list of all available test classes 221 * 222 * @return An array of the test classes 223 */ 224 public static Class<Test>[] getAllAvailableTests() { 225 return allAvailableTests; 226 } 227 228 /** 229 * Initializes all tests 230 * @param allTests The tests to initialize 231 */ 232 public void initializeTests(Collection<Test> allTests) { 233 for (Test test : allTests) { 234 try { 235 if (test.enabled) { 236 test.getClass().getMethod("initialize", new Class[] { OSMValidatorPlugin.class }).invoke(null, 237 new Object[] { this }); 238 } 239 } catch (InvocationTargetException ite) { 240 ite.getCause().printStackTrace(); 241 JOptionPane.showMessageDialog(null, tr("Error initializing test {0}:\n {1}", test.getClass() 242 .getSimpleName(), ite.getCause().getMessage())); 243 } catch (Exception e) { 244 e.printStackTrace(); 245 JOptionPane.showMessageDialog(null, tr("Error initializing test {0}:\n {1}", test.getClass() 246 .getSimpleName(), e)); 247 } 248 } 249 } 250 251 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 252 if (newLayer instanceof OsmDataLayer) { 253 List<TestError> errors = layerErrors.get(newLayer); 254 validationDialog.tree.setErrorList(errors); 255 Main.map.repaint(); 256 } 257 } 258 259 public void layerAdded(Layer newLayer) { 260 if (newLayer instanceof OsmDataLayer) { 261 layerErrors.put(newLayer, new ArrayList<TestError>()); 262 } 263 } 264 265 public void layerRemoved(Layer oldLayer) { 266 layerErrors.remove(oldLayer); 267 } 271 268 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java
r10502 r10663 23 23 * @author frsantos 24 24 */ 25 public class ValidateAction extends JosmAction 26 { 27 private OSMValidatorPlugin plugin; 25 public class ValidateAction extends JosmAction { 26 private OSMValidatorPlugin plugin; 28 27 29 30 28 /** Serializable ID */ 29 private static final long serialVersionUID = -2304521273582574603L; 31 30 32 33 31 /** Last selection used to validate */ 32 private Collection<OsmPrimitive> lastSelection; 34 33 35 36 37 38 39 super(tr("Validation"), "validator", tr("Performs the data validation"), 40 KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK+ KeyEvent.ALT_MASK, true);41 42 34 /** 35 * Constructor 36 */ 37 public ValidateAction(OSMValidatorPlugin plugin) { 38 super(tr("Validation"), "validator", tr("Performs the data validation"), KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK 39 + KeyEvent.ALT_MASK, true); 40 this.plugin = plugin; 41 } 43 42 44 public void actionPerformed(ActionEvent ev) 45 { 46 doValidate(ev, true); 47 } 43 public void actionPerformed(ActionEvent ev) { 44 doValidate(ev, true); 45 } 48 46 49 /** 50 * Does the validation. 51 * <p> 52 * If getSelectedItems is true, the selected items (or all items, if no one 53 * is selected) are validated. If it is false, last selected items are 54 * revalidated 55 * 56 * @param ev The event 57 * @param getSelectedItems If selected or last selected items must be validated 58 */ 59 public void doValidate(@SuppressWarnings("unused") ActionEvent ev, boolean getSelectedItems) 60 { 61 if( plugin.validateAction == null || Main.map == null || !Main.map.isVisible() ) 62 return; 47 /** 48 * Does the validation. 49 * <p> 50 * If getSelectedItems is true, the selected items (or all items, if no one 51 * is selected) are validated. If it is false, last selected items are 52 * revalidated 53 * 54 * @param ev The event 55 * @param getSelectedItems If selected or last selected items must be validated 56 */ 57 public void doValidate(ActionEvent ev, boolean getSelectedItems) { 58 if (plugin.validateAction == null || Main.map == null || !Main.map.isVisible()) 59 return; 63 60 64 Collection<Test> tests = OSMValidatorPlugin.getEnabledTests(false); 65 if( tests.isEmpty() ) 66 return; 61 OSMValidatorPlugin.plugin.initializeErrorLayer(); 67 62 68 Collection<OsmPrimitive> selection; 69 if( getSelectedItems ) 70 { 71 selection = Main.ds.getSelected(); 72 if( selection.isEmpty() ) 73 { 74 selection = Main.ds.allNonDeletedPrimitives(); 75 lastSelection = null; 76 } 77 else 78 { 79 AgregatePrimitivesVisitor v = new AgregatePrimitivesVisitor(); 80 selection = v.visit(selection); 81 lastSelection = selection; 82 } 83 } 84 else 85 { 86 if( lastSelection == null ) 87 selection = Main.ds.allNonDeletedPrimitives(); 88 else 89 selection = lastSelection; 90 } 63 Collection<Test> tests = OSMValidatorPlugin.getEnabledTests(false); 64 if (tests.isEmpty()) 65 return; 91 66 92 List<TestError> errors = new ArrayList<TestError>(); 93 for(Test test : tests) 94 { 95 test.setPartialSelection(lastSelection != null); 96 test.startTest(); 97 test.visit(selection); 98 test.endTest(); 99 errors.addAll( test.getErrors() ); 100 } 101 tests = null; 102 if(Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) 103 { 104 for(TestError error : errors) 105 { 106 List<String> s = new ArrayList<String>(); 107 s.add(error.getIgnoreState()); 108 s.add(error.getIgnoreGroup()); 109 s.add(error.getIgnoreSubGroup()); 110 for(String state : s) 111 { 112 if(state != null && plugin.ignoredErrors.contains(state)) 113 { 114 error.setIgnored(true); 115 } 116 } 117 } 118 } 67 Collection<OsmPrimitive> selection; 68 if (getSelectedItems) { 69 selection = Main.ds.getSelected(); 70 if (selection.isEmpty()) { 71 selection = Main.ds.allNonDeletedPrimitives(); 72 lastSelection = null; 73 } else { 74 AgregatePrimitivesVisitor v = new AgregatePrimitivesVisitor(); 75 selection = v.visit(selection); 76 lastSelection = selection; 77 } 78 } else { 79 if (lastSelection == null) 80 selection = Main.ds.allNonDeletedPrimitives(); 81 else 82 selection = lastSelection; 83 } 119 84 120 plugin.validationDialog.tree.setErrors(errors); 121 plugin.validationDialog.setVisible(true); 122 DataSet.fireSelectionChanged(Main.ds.getSelected()); 123 } 85 List<TestError> errors = new ArrayList<TestError>(); 86 for (Test test : tests) { 87 test.setPartialSelection(lastSelection != null); 88 test.startTest(); 89 test.visit(selection); 90 test.endTest(); 91 errors.addAll(test.getErrors()); 92 } 93 tests = null; 94 if (Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) { 95 for (TestError error : errors) { 96 List<String> s = new ArrayList<String>(); 97 s.add(error.getIgnoreState()); 98 s.add(error.getIgnoreGroup()); 99 s.add(error.getIgnoreSubGroup()); 100 for (String state : s) { 101 if (state != null && plugin.ignoredErrors.contains(state)) { 102 error.setIgnored(true); 103 } 104 } 105 } 106 } 107 108 plugin.validationDialog.tree.setErrors(errors); 109 plugin.validationDialog.setVisible(true); 110 DataSet.fireSelectionChanged(Main.ds.getSelected()); 111 } 124 112 }
Note:
See TracChangeset
for help on using the changeset viewer.