Changeset 4087 in osm
- Timestamp:
- 2007-08-11T21:19:21+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
r4086 r4087 65 65 public OSMValidatorPlugin() 66 66 { 67 initializeTests( getTests(true) ); 67 PreferenceEditor.importOldPreferences(); 68 initializeTests( getTests(true, true) ); 68 69 } 69 70 … … 124 125 * Gets a collection with the available tests 125 126 * 126 * @param onlyActive if true, gets only active tests 127 * @param enabled if false, don't get enabled tests 128 * @param enabledBeforeUpload if false, don't get tests enabled before upload 127 129 * @return A collection with the available tests 128 130 */ 129 public static Collection<Test> getTests(boolean onlyActive)131 public static Collection<Test> getTests(boolean enabled, boolean enabledBeforeUpload) 130 132 { 131 133 Map<String, Test> enabledTests = new LinkedHashMap<String, Test>(); 132 134 for(Class<Test> testClass : getAllAvailableTests() ) 133 135 { 134 Test test;135 136 try { 136 test = testClass.newInstance(); 137 Test test = testClass.newInstance(); 138 enabledTests.put(testClass.getSimpleName(), test); 137 139 } 138 140 catch( Exception e) … … 141 143 continue; 142 144 } 143 test.enabled = true;144 145 String simpleName = testClass.getSimpleName();146 test.testBeforeUpload = Main.pref.getBoolean( "tests." + simpleName + ".checkBeforeUpload", true);147 enabledTests.put(simpleName, test);148 145 } 149 146 150 147 Pattern regexp = Pattern.compile("(\\w+)=(true|false),?"); 151 Matcher m = regexp.matcher(Main.pref.get( "tests"));148 Matcher m = regexp.matcher(Main.pref.get(PreferenceEditor.PREF_TESTS)); 152 149 int pos = 0; 153 150 while( m.find(pos) ) … … 157 154 if( test != null ) 158 155 { 159 test.enabled = Boolean.valueOf(m.group(2)).booleanValue(); 160 if( onlyActive && !test.enabled) 156 test.enabled = Boolean.valueOf(m.group(2)); 157 } 158 pos = m.end(); 159 } 160 161 m = regexp.matcher(Main.pref.get( PreferenceEditor.PREF_TESTS_BEFORE_UPLOAD )); 162 pos = 0; 163 while( m.find(pos) ) 164 { 165 String testName = m.group(1); 166 Test test = enabledTests.get(testName); 167 if( test != null ) 168 { 169 test.testBeforeUpload = Boolean.valueOf(m.group(2)); 170 if( !enabled && test.enabled || !enabledBeforeUpload && test.testBeforeUpload) 161 171 enabledTests.remove(test.getClass().getSimpleName() ); 162 172 } 163 173 pos = m.end(); 164 174 } 175 165 176 return enabledTests.values(); 166 177 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/PreferenceEditor.java
r2792 r4087 4 4 5 5 import java.awt.GridBagLayout; 6 import java.awt.event.ActionEvent;7 import java.awt.event.ActionListener;8 6 import java.util.Collection; 7 import java.util.Map; 8 import java.util.regex.Pattern; 9 9 10 10 import javax.swing.*; … … 24 24 public class PreferenceEditor implements PreferenceSetting 25 25 { 26 /** The preferences prefix */ 27 public static final String PREFIX = "validator"; 28 29 /** The preferences key for enabled tests */ 30 public static final String PREF_TESTS = PREFIX + ".tests"; 31 32 /** The preferences key for enabled tests before upload*/ 33 public static final String PREF_TESTS_BEFORE_UPLOAD = PREFIX + ".testsBeforeUpload"; 34 26 35 /** The list of all tests */ 27 36 private Collection<Test> allTests; … … 35 44 testPanel.add( new JLabel("On upload"), GBC.eop() ); 36 45 37 allTests = OSMValidatorPlugin.getTests( false);38 for( finalTest test: allTests)46 allTests = OSMValidatorPlugin.getTests(true, true); 47 for(Test test: allTests) 39 48 { 40 final JCheckBox testCheck = new JCheckBox(test.name, test.enabled);41 testCheck.setToolTipText(test.description);42 testPanel.add(testCheck, GBC.std().insets(20,0,0,0));43 44 testCheck.addActionListener(new ActionListener(){45 public void actionPerformed(ActionEvent e) {46 boolean selected = testCheck.isSelected();47 test.enabled = selected;48 test.setGuiEnabled(selected );49 }50 });51 52 49 test.addGui(testPanel); 53 test.setGuiEnabled(test.enabled );50 test.setGuiEnabled(test.enabled || test.testBeforeUpload); 54 51 } 55 52 … … 68 65 public void ok() 69 66 { 70 String tests = ""; 67 StringBuilder tests = new StringBuilder(); 68 StringBuilder testsBeforeUpload = new StringBuilder(); 71 69 72 70 for (Test test : allTests) 73 71 { 74 boolean enabled = test.enabled;72 test.ok(); 75 73 String name = test.getClass().getSimpleName(); 76 tests += name + "=" + enabled + ","; 77 78 if (enabled) 79 { 80 test.ok(); 81 } 74 tests.append( ',' ).append( name ).append( '=' ).append( test.enabled ); 75 testsBeforeUpload.append( ',' ).append( name ).append( '=' ).append( test.testBeforeUpload ); 82 76 } 83 77 84 if (tests. endsWith(","))85 tests = tests.substring(0, tests.length() - 1);78 if (tests.length() > 0 ) tests = tests.deleteCharAt(0); 79 if (testsBeforeUpload.length() > 0 ) testsBeforeUpload = testsBeforeUpload.deleteCharAt(0); 86 80 87 81 OSMValidatorPlugin.getPlugin().initializeTests( allTests ); 88 82 89 Main.pref.put("tests", tests); 83 Main.pref.put( PREF_TESTS, tests.toString()); 84 Main.pref.put( PREF_TESTS_BEFORE_UPLOAD, testsBeforeUpload.toString()); 85 } 86 87 /** 88 * Import old stored preferences 89 */ 90 public static void importOldPreferences() 91 { 92 if( !Main.pref.hasKey("tests") || !Pattern.matches("(\\w+=(true|false),?)*", Main.pref.get("tests")) ) 93 return; 94 95 String enabledTests = Main.pref.get("tests"); 96 Main.pref.put(PREF_TESTS, enabledTests); 97 Main.pref.put("tests", null ); 98 99 StringBuilder testsBeforeUpload = new StringBuilder(); 100 Map<String, String> oldPrefs = Main.pref.getAllPrefix("tests"); 101 for( Map.Entry<String, String> pref : oldPrefs.entrySet() ) 102 { 103 String key = pref.getKey(); 104 String value = pref.getValue(); 105 if( key.endsWith(".checkBeforeUpload") ) 106 { 107 String testName = key.substring(6, key.length() - 18); 108 testsBeforeUpload.append( ',' ).append( testName ).append( '=' ).append( value ); 109 } 110 else 111 Main.pref.put( PREFIX + key.substring(5), value ); 112 Main.pref.put(key, null ); 113 } 114 115 if (testsBeforeUpload.length() > 0 ) testsBeforeUpload = testsBeforeUpload.deleteCharAt(0); 116 Main.pref.put( PREF_TESTS_BEFORE_UPLOAD, testsBeforeUpload.toString()); 90 117 } 91 118 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/Test.java
r2792 r4087 1 1 package org.openstreetmap.josm.plugins.validator; 2 2 3 import java.util.*; 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 import java.util.ArrayList; 6 import java.util.Collection; 7 import java.util.List; 4 8 5 9 import javax.swing.JCheckBox; 6 10 import javax.swing.JPanel; 7 11 8 import org.openstreetmap.josm.Main;9 12 import org.openstreetmap.josm.command.Command; 10 13 import org.openstreetmap.josm.data.osm.*; … … 29 32 protected String description; 30 33 31 /** Whether this test is enabled. Used by peferences */ 32 protected boolean enabled; 34 /** Whether this test is enabled. Enabled by default */ 35 protected boolean enabled = true; 36 37 /** The preferences check for validation */ 38 protected JCheckBox checkEnabled; 33 39 34 40 /** The preferences check for validation on upload */ 35 41 protected JCheckBox checkBeforeUpload; 36 42 37 /** Whether this test must check before upload. Used by peferences*/38 protected boolean testBeforeUpload ;43 /** Whether this test must check before upload. Enabled by default */ 44 protected boolean testBeforeUpload = true; 39 45 40 46 /** Whether this test is performing just before an upload */ … … 134 140 public void addGui(@SuppressWarnings("unused") JPanel testPanel) 135 141 { 142 checkEnabled = new JCheckBox(name, enabled); 143 checkEnabled.setToolTipText(description); 144 checkEnabled.addActionListener(new ActionListener(){ 145 public void actionPerformed(ActionEvent e) { 146 setGuiEnabled(checkEnabled.isSelected() || checkBeforeUpload.isSelected() ); 147 } 148 }); 149 testPanel.add(checkEnabled, GBC.std().insets(20,0,0,0)); 150 136 151 checkBeforeUpload = new JCheckBox(); 137 152 checkBeforeUpload.setSelected(testBeforeUpload); 153 checkBeforeUpload.addActionListener(new ActionListener(){ 154 public void actionPerformed(ActionEvent e) { 155 setGuiEnabled(checkEnabled.isSelected() || checkBeforeUpload.isSelected() ); 156 } 157 }); 138 158 testPanel.add(checkBeforeUpload, GBC.eop().insets(20,0,0,0)); 139 159 } … … 145 165 public void setGuiEnabled(boolean enabled) 146 166 { 147 checkBeforeUpload.setEnabled(enabled);148 167 } 149 168 … … 153 172 public void ok() 154 173 { 155 String simpleName = getClass().getSimpleName();156 Main.pref.put("tests." + simpleName + ".checkBeforeUpload", checkBeforeUpload.isSelected());174 enabled = checkEnabled.isSelected(); 175 testBeforeUpload = checkBeforeUpload.isSelected(); 157 176 } 158 177 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java
r4023 r4087 58 58 return; 59 59 60 Collection<Test> tests = OSMValidatorPlugin.getTests(true );60 Collection<Test> tests = OSMValidatorPlugin.getTests(true, false); 61 61 if( tests.isEmpty() ) 62 62 return; -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateUploadHook.java
r3037 r4087 32 32 public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) 33 33 { 34 Collection<Test> tests = OSMValidatorPlugin.getTests( true);34 Collection<Test> tests = OSMValidatorPlugin.getTests(false, true); 35 35 if( tests.isEmpty() ) 36 36 return true; -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/SpellCheck.java
r4025 r4087 41 41 /** The spell check preset values */ 42 42 protected static Bag<String, String> spellCheckValueData; 43 43 44 /** The preferences prefix */ 45 protected static final String PREFIX = PreferenceEditor.PREFIX + "." + SpellCheck.class.getSimpleName(); 46 44 47 /** Preference name for checking values */ 45 public static final String PREF_CHECK_VALUES = "tests." + SpellCheck.class.getSimpleName()+ ".checkValues";48 public static final String PREF_CHECK_VALUES = PREFIX + ".checkValues"; 46 49 /** Preference name for checking values */ 47 public static final String PREF_CHECK_KEYS = "tests." + SpellCheck.class.getSimpleName()+ ".checkKeys";50 public static final String PREF_CHECK_KEYS = PREFIX + ".checkKeys"; 48 51 /** Preference name for checking FIXMES */ 49 public static final String PREF_CHECK_FIXMES = "tests." + SpellCheck.class.getSimpleName()+ ".checkFixmes";52 public static final String PREF_CHECK_FIXMES = PREFIX + ".checkFixmes"; 50 53 /** Preference name for sources */ 51 public static final String PREF_SOURCES = "tests." + SpellCheck.class.getSimpleName() + ".sources"; 52 /** Preference name for global upload check */ 53 public static final String PREF_CHECK_BEFORE_UPLOAD = "tests." + SpellCheck.class.getSimpleName() + ".checkBeforeUpload"; 54 public static final String PREF_SOURCES = PREFIX + ".sources"; 54 55 /** Preference name for keys upload check */ 55 public static final String PREF_CHECK_KEYS_BEFORE_UPLOAD = "tests." + SpellCheck.class.getSimpleName()+ ".checkKeysBeforeUpload";56 public static final String PREF_CHECK_KEYS_BEFORE_UPLOAD = PREFIX + ".checkKeysBeforeUpload"; 56 57 /** Preference name for values upload check */ 57 public static final String PREF_CHECK_VALUES_BEFORE_UPLOAD = "tests." + SpellCheck.class.getSimpleName()+ ".checkValuesBeforeUpload";58 public static final String PREF_CHECK_VALUES_BEFORE_UPLOAD = PREFIX + ".checkValuesBeforeUpload"; 58 59 /** Preference name for fixmes upload check */ 59 public static final String PREF_CHECK_FIXMES_BEFORE_UPLOAD = "tests." + SpellCheck.class.getSimpleName()+ ".checkFixmesBeforeUpload";60 public static final String PREF_CHECK_FIXMES_BEFORE_UPLOAD = PREFIX + ".checkFixmesBeforeUpload"; 60 61 61 62 /** Whether to check keys */ … … 364 365 public void addGui(JPanel testPanel) 365 366 { 366 testPanel.add( new JLabel(), GBC.eol());367 testPanel.add( new JLabel(name), GBC.eol().insets(35,0,0,0) ); 367 368 368 369 boolean checkKeys = Main.pref.getBoolean(PREF_CHECK_KEYS, true); … … 433 434 buttonPanel.add(deleteSrcButton, GBC.std().insets(0,5,0,0)); 434 435 435 prefCheckKeys.addActionListener(new ActionListener(){ 436 public void actionPerformed(ActionEvent e) { 437 boolean selected = prefCheckKeys.isSelected(); 438 spellcheckSources.setEnabled( selected ); 439 addSrcButton.setEnabled(selected); 440 editSrcButton.setEnabled(selected); 441 deleteSrcButton.setEnabled(selected); 442 } 443 }); 436 ActionListener disableCheckKeysActionListener = new ActionListener(){ 437 public void actionPerformed(ActionEvent e) { 438 boolean selected = prefCheckKeys.isSelected() || prefCheckKeysBeforeUpload.isSelected(); 439 spellcheckSources.setEnabled( selected ); 440 addSrcButton.setEnabled(selected); 441 editSrcButton.setEnabled(selected); 442 deleteSrcButton.setEnabled(selected); 443 } 444 }; 445 prefCheckKeys.addActionListener(disableCheckKeysActionListener); 446 prefCheckKeysBeforeUpload.addActionListener(disableCheckKeysActionListener); 444 447 445 448 spellcheckSources.setEnabled( checkKeys ); … … 465 468 } 466 469 467 public void setGuiEnabled(boolean enabled)468 {469 prefCheckKeys.setEnabled(enabled);470 prefCheckKeysBeforeUpload.setEnabled(enabled);471 spellcheckSources.setEnabled( enabled );472 addSrcButton.setEnabled(enabled);473 editSrcButton.setEnabled(enabled);474 deleteSrcButton.setEnabled(enabled);475 prefCheckValues.setEnabled(enabled);476 prefCheckValuesBeforeUpload.setEnabled(enabled);477 prefCheckFixmes.setEnabled(enabled);478 prefCheckFixmesBeforeUpload.setEnabled(enabled);479 }480 481 470 @Override 482 471 public void ok() 483 472 { 473 enabled = prefCheckKeys.isSelected() || prefCheckValues.isSelected() || prefCheckFixmes.isSelected(); 474 testBeforeUpload = prefCheckKeysBeforeUpload.isSelected() || prefCheckValuesBeforeUpload.isSelected() || prefCheckFixmesBeforeUpload.isSelected(); 475 484 476 Main.pref.put(PREF_CHECK_VALUES, prefCheckValues.isSelected()); 485 477 Main.pref.put(PREF_CHECK_KEYS, prefCheckKeys.isSelected()); … … 488 480 Main.pref.put(PREF_CHECK_KEYS_BEFORE_UPLOAD, prefCheckKeysBeforeUpload.isSelected()); 489 481 Main.pref.put(PREF_CHECK_FIXMES_BEFORE_UPLOAD, prefCheckFixmesBeforeUpload.isSelected()); 490 Main.pref.put(PREF_CHECK_BEFORE_UPLOAD, prefCheckKeysBeforeUpload.isSelected() || prefCheckValuesBeforeUpload.isSelected() || prefCheckFixmesBeforeUpload.isSelected());491 482 String sources = ""; 492 483 if( spellcheckSources.getModel().getSize() > 0 )
Note:
See TracChangeset
for help on using the changeset viewer.