Changeset 9561 in osm for applications/editors/josm/plugins/validator/src/org
- Timestamp:
- 2008-08-08T12:02:07+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java
r9454 r9561 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 5 6 import java.awt.BorderLayout; … … 25 26 import org.openstreetmap.josm.data.osm.DataSet; 26 27 import org.openstreetmap.josm.data.osm.OsmPrimitive; 28 import org.openstreetmap.josm.gui.SideButton; 27 29 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 28 30 import org.openstreetmap.josm.plugins.validator.util.Bag; … … 48 50 public Collection<String> ignoredErrors = new TreeSet<String>(); 49 51 50 /** The fix button */ 51 private JButton fixButton; 52 53 /** The ignore button */ 54 private JButton ignoreButton; 55 56 /** The select button */ 57 private JButton selectButton; 52 private SideButton fixButton; /** The fix button */ 53 private SideButton ignoreButton; /** The ignore button */ 54 private SideButton selectButton; /** The select button */ 58 55 59 56 /** Last selected element */ … … 76 73 JPanel buttonPanel = new JPanel(new GridLayout(1,3)); 77 74 78 selectButton = Util.createButton(tr("Select"), "select", "mapmode/selection/select",75 selectButton = new SideButton(marktr("Select"), "select", "Validator", 79 76 tr("Set the selected elements on the map to the selected items in the list above."), this); 80 77 selectButton.setEnabled(false); 81 78 buttonPanel.add(selectButton); 82 buttonPanel.add( Util.createButton(tr("Validate"), "validate", "dialogs/refresh", tr("Validate the data."), this));83 fixButton = Util.createButton(tr("Fix"), "fix", "dialogs/fix", tr("Fix the selected errors."), this);79 buttonPanel.add(new SideButton(marktr("Validate"), "refresh", "Validator", tr("Validate the data."), this)); 80 fixButton = new SideButton(marktr("Fix"), "fix", "Validator", tr("Fix the selected errors."), this); 84 81 fixButton.setEnabled(false); 85 82 buttonPanel.add(fixButton); 86 83 if(Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) 87 84 { 88 ignoreButton = Util.createButton(tr("Ignore"), "ignore", "dialogs/delete", tr("Ignore the selected errors next time."), this);85 ignoreButton = new SideButton(marktr("Ignore"), "delete", "Validator", tr("Ignore the selected errors next time."), this); 89 86 ignoreButton.setEnabled(false); 90 87 buttonPanel.add(ignoreButton); -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/OverlappingWays.java
r9021 r9561 7 7 import org.openstreetmap.josm.data.coor.LatLon; 8 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 import org.openstreetmap.josm.data.osm.OsmUtils; 9 10 import org.openstreetmap.josm.data.osm.Way; 10 11 import org.openstreetmap.josm.data.osm.WaySegment; … … 65 66 for (WaySegment ws : duplicated) 66 67 { 67 String ar;68 69 68 if (ws.way.get("highway") != null) 70 69 highway++; 71 70 else if (ws.way.get("railway") != null) 72 71 railway++; 73 ar = ws.way.get("area"); 74 if (ar != null && ("true".equalsIgnoreCase(ar) || "yes".equalsIgnoreCase(ar) || "1".equals(ar))) 72 if (OsmUtils.getOsmBoolean(ws.way.get("area"))) 75 73 area++; 76 74 if (ws.way.get("landuse") != null || ws.way.get("natural") != null -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java
r9279 r9561 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.GridBagLayout;6 5 import java.awt.event.ActionEvent; 7 6 import java.awt.event.ActionListener; 8 import java.io.*; 7 import java.awt.GridBagLayout; 8 import java.io.BufferedReader; 9 import java.io.File; 10 import java.io.FileInputStream; 11 import java.io.FileNotFoundException; 12 import java.io.FileReader; 13 import java.io.InputStream; 14 import java.io.InputStreamReader; 15 import java.io.IOException; 16 import java.io.UnsupportedEncodingException; 9 17 import java.net.URL; 10 import java.util.*; 18 import java.util.ArrayList; 19 import java.util.Collection; 20 import java.util.Collections; 21 import java.util.HashMap; 22 import java.util.List; 23 import java.util.Map; 11 24 import java.util.Map.Entry; 12 13 import javax.swing.*; 14 25 import java.util.StringTokenizer; 26 27 import javax.swing.DefaultListModel; 28 import javax.swing.JButton; 29 import javax.swing.JCheckBox; 30 import javax.swing.JLabel; 31 import javax.swing.JList; 32 import javax.swing.JOptionPane; 33 import javax.swing.JScrollPane; 34 import javax.swing.JPanel; 35 36 import org.openstreetmap.josm.command.ChangePropertyCommand; 37 import org.openstreetmap.josm.command.Command; 38 import org.openstreetmap.josm.command.SequenceCommand; 39 import org.openstreetmap.josm.data.osm.Node; 40 import org.openstreetmap.josm.data.osm.OsmPrimitive; 41 import org.openstreetmap.josm.data.osm.Way; 42 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 43 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 15 44 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm. command.*;17 import org.openstreetmap.josm. data.osm.*;18 import org.openstreetmap.josm. gui.tagging.TaggingPreset;19 import org.openstreetmap.josm. gui.tagging.TaggingPreset.*;20 import org.openstreetmap.josm. gui.preferences.TaggingPresetPreference;21 import org.openstreetmap.josm.plugins.validator. *;45 import org.openstreetmap.josm.plugins.validator.OSMValidatorPlugin; 46 import org.openstreetmap.josm.plugins.validator.PreferenceEditor; 47 import org.openstreetmap.josm.plugins.validator.Severity; 48 import org.openstreetmap.josm.plugins.validator.Test; 49 import org.openstreetmap.josm.plugins.validator.TestError; 50 import org.openstreetmap.josm.plugins.validator.tests.ChangePropertyKeyCommand; 22 51 import org.openstreetmap.josm.plugins.validator.util.Bag; 23 52 import org.openstreetmap.josm.plugins.validator.util.Util; … … 41 70 /** The spell check preset values */ 42 71 protected static Bag<String, String> presetsValueData; 72 /** The TagChecker data */ 73 protected static List<CheckerData> checkerData = new ArrayList<CheckerData>(); 43 74 44 75 /** The preferences prefix */ 45 76 protected static final String PREFIX = PreferenceEditor.PREFIX + "." + TagChecker.class.getSimpleName(); 46 77 47 /** Preference name for checking values */48 78 public static final String PREF_CHECK_VALUES = PREFIX + ".checkValues"; 49 /** Preference name for checking values */50 79 public static final String PREF_CHECK_KEYS = PREFIX + ".checkKeys"; 51 /** Preference name for checking FIXMES */80 public static final String PREF_CHECK_COMPLEX = PREFIX + ".checkComplex"; 52 81 public static final String PREF_CHECK_FIXMES = PREFIX + ".checkFixmes"; 53 /** Preference name for sources */ 82 54 83 public static final String PREF_SOURCES = PREFIX + ".sources"; 55 /** Preference name for sources */56 84 public static final String PREF_USE_DATA_FILE = PREFIX + ".usedatafile"; 57 /** Preference name for sources */58 85 public static final String PREF_USE_SPELL_FILE = PREFIX + ".usespellfile"; 59 /** Preference name for keys upload check */ 86 60 87 public static final String PREF_CHECK_KEYS_BEFORE_UPLOAD = PREFIX + ".checkKeysBeforeUpload"; 61 /** Preference name for values upload check */62 88 public static final String PREF_CHECK_VALUES_BEFORE_UPLOAD = PREFIX + ".checkValuesBeforeUpload"; 63 /** Preference name for fixmes upload check */89 public static final String PREF_CHECK_COMPLEX_BEFORE_UPLOAD = PREFIX + ".checkComplexBeforeUpload"; 64 90 public static final String PREF_CHECK_FIXMES_BEFORE_UPLOAD = PREFIX + ".checkFixmesBeforeUpload"; 65 91 66 /** Whether to check keys */67 92 protected boolean checkKeys = false; 68 /** Whether to check values */69 93 protected boolean checkValues = false; 70 /** Whether to check for fixmes in values */94 protected boolean checkComplex = false; 71 95 protected boolean checkFixmes = false; 72 96 73 /** Preferences checkbox for keys */74 97 protected JCheckBox prefCheckKeys; 75 /** Preferences checkbox for values */76 98 protected JCheckBox prefCheckValues; 77 /** Preferences checkbox for FIXMES */99 protected JCheckBox prefCheckComplex; 78 100 protected JCheckBox prefCheckFixmes; 79 /** The preferences checkbox for validation of keys on upload */ 101 80 102 protected JCheckBox prefCheckKeysBeforeUpload; 81 /** The preferences checkbox for validation of values on upload */82 103 protected JCheckBox prefCheckValuesBeforeUpload; 83 /** The preferences checkbox for validation of fixmes on upload */104 protected JCheckBox prefCheckComplexBeforeUpload; 84 105 protected JCheckBox prefCheckFixmesBeforeUpload; 85 /** The add button */ 106 107 protected JCheckBox prefUseDataFile; 108 protected JCheckBox prefUseSpellFile; 109 86 110 protected JButton addSrcButton; 87 /** The edit button */88 111 protected JButton editSrcButton; 89 /** The delete button */90 112 protected JButton deleteSrcButton; 91 113 92 protected static int EMPTY_VALUES = 0; /** Empty values error */ 93 protected static int INVALID_KEY = 1; /** Invalid key error */ 94 protected static int INVALID_VALUE = 2; /** Invalid value error */ 95 protected static int FIXME = 3; /** fixme error */ 96 protected static int INVALID_SPACE = 3; /** space in value (start/end) */ 114 protected static int EMPTY_VALUES = 0; 115 protected static int INVALID_KEY = 1; 116 protected static int INVALID_VALUE = 2; 117 protected static int FIXME = 3; 118 protected static int INVALID_SPACE = 3; 119 protected static int TAG_CHECK = 4; 97 120 98 121 /** List of sources for spellcheck data */ 99 122 protected JList Sources; 100 101 /** Whether this test must check the keys before upload. Used by peferences */102 protected boolean testKeysBeforeUpload;103 /** Whether this test must check the values before upload. Used by peferences */104 protected boolean testValuesBeforeUpload;105 /** Whether this test must check form fixmes in values before upload. Used by peferences */106 protected boolean testFixmesBeforeUpload;107 123 108 124 /** … … 165 181 166 182 String okValue = null; 183 Boolean tagcheckerfile = false; 167 184 do 168 185 { 169 186 String line = reader.readLine(); 170 if( line == null || line.length() == 0)187 if( line == null || (!tagcheckerfile && line.length() == 0) ) 171 188 break; 172 189 if( line.startsWith("#") ) 173 continue; 174 175 if( line.charAt(0) == '+' ) 190 { 191 if(line.startsWith("# JOSM TagChecker")) 192 tagcheckerfile = true; 193 } 194 else if(tagcheckerfile) 195 { 196 CheckerData d = new CheckerData(); 197 String err = d.getData(line); 198 199 if(err == null) 200 checkerData.add(d); 201 else 202 System.err.println("Invalid tagchecker line - "+err+":" + line); 203 } 204 else if( line.charAt(0) == '+' ) 176 205 { 177 206 okValue = line.substring(1); … … 237 266 Bag<OsmPrimitive, String> withErrors = new Bag<OsmPrimitive, String>(); 238 267 268 if(checkComplex) 269 { 270 for(CheckerData d : checkerData) 271 { 272 if(d.match(p)) 273 { 274 errors.add( new TestError(this, Severity.WARNING, tr("Illegal tag/value combinations"), p, TAG_CHECK) ); 275 withErrors.add(p, "TC"); 276 break; 277 } 278 } 279 } 280 239 281 Map<String, String> props = (p.keys == null) ? Collections.<String, String>emptyMap() : p.keys; 240 282 for(Entry<String, String> prop: props.entrySet() ) … … 304 346 XmlObjectParser parser = new XmlObjectParser(); 305 347 parser.mapOnStart("item", TaggingPreset.class); 306 parser.map("text", T ext.class);307 parser.map("check", Check.class);308 parser.map("combo", Combo.class);309 parser.map("label", Label.class);310 parser.map("key", Key.class);348 parser.map("text", TaggingPreset.Text.class); 349 parser.map("check", TaggingPreset.Check.class); 350 parser.map("combo", TaggingPreset.Combo.class); 351 parser.map("label", TaggingPreset.Label.class); 352 parser.map("key", TaggingPreset.Key.class); 311 353 parser.start(in); 312 354 … … 314 356 { 315 357 Object obj = parser.next(); 316 if (obj instanceof Combo) {317 Combo combo = (Combo)obj;358 if (obj instanceof TaggingPreset.Combo) { 359 TaggingPreset.Combo combo = (TaggingPreset.Combo)obj; 318 360 for(String value : combo.values.split(",") ) 319 361 presetsValueData.add(combo.key, value); … … 366 408 checkValues = checkValues && Main.pref.getBoolean(PREF_CHECK_VALUES_BEFORE_UPLOAD, true); 367 409 410 checkComplex = Main.pref.getBoolean(PREF_CHECK_COMPLEX); 411 if( isBeforeUpload ) 412 checkComplex = checkValues && Main.pref.getBoolean(PREF_CHECK_COMPLEX_BEFORE_UPLOAD, true); 413 368 414 checkFixmes = Main.pref.getBoolean(PREF_CHECK_FIXMES); 369 415 if( isBeforeUpload ) … … 374 420 public void visit(Collection<OsmPrimitive> selection) 375 421 { 376 if( checkKeys || checkValues )422 if( checkKeys || checkValues || checkComplex) 377 423 super.visit(selection); 378 424 } … … 385 431 386 432 testPanel.add( new JLabel(name), GBC.eol().insets(3,0,0,0) ); 387 388 boolean checkKeys = Main.pref.getBoolean(PREF_CHECK_KEYS, true); 389 prefCheckKeys = new JCheckBox(tr("Check property keys."), checkKeys); 433 434 prefCheckKeys = new JCheckBox(tr("Check property keys."), Main.pref.getBoolean(PREF_CHECK_KEYS, true)); 390 435 prefCheckKeys.setToolTipText(tr("Validate that property keys are valid checking against list of words.")); 391 436 testPanel.add(prefCheckKeys, GBC.std().insets(20,0,0,0)); … … 394 439 prefCheckKeysBeforeUpload.setSelected(Main.pref.getBoolean(PREF_CHECK_KEYS_BEFORE_UPLOAD, true)); 395 440 testPanel.add(prefCheckKeysBeforeUpload, a); 441 442 prefCheckComplex = new JCheckBox(tr("Use complex property checker."), Main.pref.getBoolean(PREF_CHECK_COMPLEX, true)); 443 prefCheckComplex.setToolTipText(tr("Validate property values and tags using complex rules.")); 444 testPanel.add(prefCheckComplex, GBC.std().insets(20,0,0,0)); 445 446 prefCheckComplexBeforeUpload = new JCheckBox(); 447 prefCheckComplexBeforeUpload.setSelected(Main.pref.getBoolean(PREF_CHECK_COMPLEX_BEFORE_UPLOAD, true)); 448 testPanel.add(prefCheckComplexBeforeUpload, a); 396 449 397 450 Sources = new JList(new DefaultListModel()); … … 468 521 buttonPanel.add(deleteSrcButton, GBC.std().insets(0,5,0,0)); 469 522 470 ActionListener disableCheck KeysActionListener = new ActionListener(){523 ActionListener disableCheckActionListener = new ActionListener(){ 471 524 public void actionPerformed(ActionEvent e) { 472 boolean selected = prefCheckKeys.isSelected() || prefCheckKeysBeforeUpload.isSelected(); 473 Sources.setEnabled( selected ); 474 addSrcButton.setEnabled(selected); 475 editSrcButton.setEnabled(selected); 476 deleteSrcButton.setEnabled(selected); 525 handlePrefEnable(); 477 526 } 478 527 }; 479 prefCheckKeys.addActionListener(disableCheck KeysActionListener);480 prefCheckKeysBeforeUpload.addActionListener(disableCheck KeysActionListener);481 482 Sources.setEnabled( checkKeys);483 buttonPanel.setEnabled( checkKeys ); 484 485 boolean checkValues = Main.pref.getBoolean(PREF_CHECK_VALUES, true); 486 prefCheckValues = new JCheckBox(tr("Check property values."), checkValues);528 prefCheckKeys.addActionListener(disableCheckActionListener); 529 prefCheckKeysBeforeUpload.addActionListener(disableCheckActionListener); 530 prefCheckComplex.addActionListener(disableCheckActionListener); 531 prefCheckComplexBeforeUpload.addActionListener(disableCheckActionListener); 532 533 handlePrefEnable(); 534 535 prefCheckValues = new JCheckBox(tr("Check property values."), Main.pref.getBoolean(PREF_CHECK_VALUES, true)); 487 536 prefCheckValues.setToolTipText(tr("Validate that property values are valid checking against presets.")); 488 537 testPanel.add(prefCheckValues, GBC.std().insets(20,0,0,0)); … … 492 541 testPanel.add(prefCheckValuesBeforeUpload, a); 493 542 494 boolean checkFixmes = Main.pref.getBoolean(PREF_CHECK_FIXMES, true); 495 prefCheckFixmes = new JCheckBox(tr("Check for FIXMES."), checkFixmes); 543 prefCheckFixmes = new JCheckBox(tr("Check for FIXMES."), Main.pref.getBoolean(PREF_CHECK_FIXMES, true)); 496 544 prefCheckFixmes.setToolTipText(tr("Looks for nodes or ways with FIXME in any property value.")); 497 545 testPanel.add(prefCheckFixmes, GBC.std().insets(20,0,0,0)); … … 501 549 testPanel.add(prefCheckFixmesBeforeUpload, a); 502 550 503 boolean useDataFile = Main.pref.getBoolean(PREF_USE_DATA_FILE, true); 504 JCheckBox prefUseDataFile = new JCheckBox(tr("Use default data file."), checkValues); 551 prefUseDataFile = new JCheckBox(tr("Use default data file."), Main.pref.getBoolean(PREF_USE_DATA_FILE, true)); 505 552 prefUseDataFile.setToolTipText(tr("Use the default data file (recommended).")); 506 553 testPanel.add(prefUseDataFile, GBC.eol().insets(20,0,0,0)); 507 554 508 boolean useSpellFile = Main.pref.getBoolean(PREF_USE_SPELL_FILE, true); 509 JCheckBox prefUseSpellFile = new JCheckBox(tr("Use default spellcheck file."), checkValues); 555 prefUseSpellFile = new JCheckBox(tr("Use default spellcheck file."), Main.pref.getBoolean(PREF_USE_SPELL_FILE, true)); 510 556 prefUseSpellFile.setToolTipText(tr("Use the default spellcheck file (recommended).")); 511 557 testPanel.add(prefUseSpellFile, GBC.eol().insets(20,0,0,0)); 512 558 } 513 559 560 public void handlePrefEnable() 561 { 562 boolean selected = prefCheckKeys.isSelected() || prefCheckKeysBeforeUpload.isSelected() 563 || prefCheckComplex.isSelected() || prefCheckComplexBeforeUpload.isSelected(); 564 Sources.setEnabled( selected ); 565 addSrcButton.setEnabled(selected); 566 editSrcButton.setEnabled(selected); 567 deleteSrcButton.setEnabled(selected); 568 } 569 514 570 @Override 515 571 public void ok() 516 572 { 517 enabled = prefCheckKeys.isSelected() || prefCheckValues.isSelected() || prefCheck Fixmes.isSelected();518 testBeforeUpload = prefCheckKeysBeforeUpload.isSelected() || prefCheckValuesBeforeUpload.isSelected() || prefCheckFixmesBeforeUpload.isSelected() ;573 enabled = prefCheckKeys.isSelected() || prefCheckValues.isSelected() || prefCheckComplex.isSelected() || prefCheckFixmes.isSelected(); 574 testBeforeUpload = prefCheckKeysBeforeUpload.isSelected() || prefCheckValuesBeforeUpload.isSelected() || prefCheckFixmesBeforeUpload.isSelected() || prefCheckComplexBeforeUpload.isSelected(); 519 575 520 576 Main.pref.put(PREF_CHECK_VALUES, prefCheckValues.isSelected()); 577 Main.pref.put(PREF_CHECK_COMPLEX, prefCheckComplex.isSelected()); 521 578 Main.pref.put(PREF_CHECK_KEYS, prefCheckKeys.isSelected()); 522 579 Main.pref.put(PREF_CHECK_FIXMES, prefCheckFixmes.isSelected()); 523 580 Main.pref.put(PREF_CHECK_VALUES_BEFORE_UPLOAD, prefCheckValuesBeforeUpload.isSelected()); 581 Main.pref.put(PREF_CHECK_COMPLEX_BEFORE_UPLOAD, prefCheckComplexBeforeUpload.isSelected()); 524 582 Main.pref.put(PREF_CHECK_KEYS_BEFORE_UPLOAD, prefCheckKeysBeforeUpload.isSelected()); 525 583 Main.pref.put(PREF_CHECK_FIXMES_BEFORE_UPLOAD, prefCheckFixmesBeforeUpload.isSelected()); 526 Main.pref.put(PREF_USE_DATA_FILE, pref CheckFixmesBeforeUpload.isSelected());527 Main.pref.put(PREF_USE_SPELL_FILE, pref CheckFixmesBeforeUpload.isSelected());584 Main.pref.put(PREF_USE_DATA_FILE, prefUseDataFile.isSelected()); 585 Main.pref.put(PREF_USE_SPELL_FILE, prefUseSpellFile.isSelected()); 528 586 String sources = ""; 529 587 if( Sources.getModel().getSize() > 0 ) … … 587 645 return false; 588 646 } 647 648 private static class CheckerData { 649 public String getData(String data) 650 { 651 System.out.println(data); 652 return "not implemented yet"; 653 } 654 public Boolean match(OsmPrimitive osm) 655 { 656 return false; 657 } 658 } 589 659 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/util/Util.java
r9454 r9561 37 37 } 38 38 39 /**40 * Utility method for creating buttons41 * @param name The name of the button42 * @param icon Icon of the button43 * @param tooltip Tooltip44 * @param action The action performed when clicking the button45 * @return The created button46 */47 public static JButton createButton(String name, String actionname, String icon, String tooltip, ActionListener action)48 {49 JButton button = new JButton(name, ImageProvider.get(icon));50 button.setActionCommand(actionname);51 button.addActionListener(action);52 button.setToolTipText(tr(tooltip));53 button.setMargin(new Insets(1,1,1,1));54 button.setIconTextGap(2);55 button.putClientProperty("help", "Dialog/SelectionList/" + actionname);56 return button;57 }58 59 60 39 /** 61 40 * Returns the version
Note:
See TracChangeset
for help on using the changeset viewer.