Changeset 6388 in osm for applications/editors/josm/plugins
- Timestamp:
- 2008-01-14T19:38:29+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
r6386 r6388 64 64 { 65 65 PreferenceEditor.importOldPreferences(); 66 initializeTests( get AllTests() );66 initializeTests( getTests() ); 67 67 } 68 68 … … 129 129 } 130 130 } 131 applyPrefs(tests, false); 132 applyPrefs(tests, true); 131 133 return tests; 132 134 } 133 135 134 /** Gets a collection of all tests. */ 135 public static Collection<Test> getAllTests() { 136 return getAllTestsMap().values(); 137 } 138 139 /** 140 * Gets a collection with the available tests 141 * 142 * @param enabled if false, don't get enabled tests 143 * @param enabledBeforeUpload if false, don't get tests enabled before upload 144 * @return A collection with the available tests 145 */ 146 public static Collection<Test> getTests(boolean enabled, boolean enabledBeforeUpload) 147 { 148 Set<Test> tests = new HashSet<Test>(); 149 Map<String, Test> enabledTests = getAllTestsMap(); 150 136 private static void applyPrefs(Map<String, Test> tests, boolean beforeUpload) { 151 137 Pattern regexp = Pattern.compile("(\\w+)=(true|false),?"); 152 Matcher m = regexp.matcher(Main.pref.get(PreferenceEditor.PREF_TESTS)); 138 Matcher m = regexp.matcher(Main.pref.get(beforeUpload 139 ? PreferenceEditor.PREF_TESTS_BEFORE_UPLOAD 140 : PreferenceEditor.PREF_TESTS)); 153 141 int pos = 0; 154 142 while( m.find(pos) ) 155 143 { 156 144 String testName = m.group(1); 157 Test test = enabledTests.get(testName);145 Test test = tests.get(testName); 158 146 if( test != null ) 159 147 { 160 test.enabled = Boolean.valueOf(m.group(2)); 161 if( enabled && test.enabled ) 162 tests.add(test ); 148 boolean enabled = Boolean.valueOf(m.group(2)); 149 System.err.println(beforeUpload + " " + testName + " " + enabled); 150 if (beforeUpload) { 151 test.testBeforeUpload = enabled; 152 } else { 153 test.enabled = enabled; 154 } 163 155 } 164 156 pos = m.end(); 165 157 } 166 167 m = regexp.matcher(Main.pref.get( PreferenceEditor.PREF_TESTS_BEFORE_UPLOAD )); 168 pos = 0; 169 while( m.find(pos) ) 170 { 171 String testName = m.group(1); 172 Test test = enabledTests.get(testName); 173 if( test != null ) 174 { 175 test.testBeforeUpload = Boolean.valueOf(m.group(2)); 176 if( enabledBeforeUpload && test.testBeforeUpload) 177 tests.add(test ); 178 } 179 pos = m.end(); 180 } 181 182 return tests; 183 } 184 158 } 159 160 public static Collection<Test> getTests() { 161 return getAllTestsMap().values(); 162 } 163 164 public static Collection<Test> getEnabledTests(boolean beforeUpload) { 165 Collection<Test> enabledTests = getTests(); 166 for (Test t : new ArrayList<Test>(enabledTests)) { 167 if (beforeUpload ? t.testBeforeUpload : t.enabled) continue; 168 enabledTests.remove(t); 169 } 170 return enabledTests; 171 } 172 185 173 /** 186 174 * Gets the list of all available test classes -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/PreferenceEditor.java
r4866 r6388 46 46 testPanel.add( new JLabel(), GBC.std() ); 47 47 testPanel.add( new JLabel("On upload"), GBC.eop() ); 48 49 allTests = OSMValidatorPlugin.get AllTests();48 49 allTests = OSMValidatorPlugin.getTests(); 50 50 for(Test test: allTests) 51 51 { 52 52 test.addGui(testPanel); 53 test.setGuiEnabled(test.enabled || test.testBeforeUpload);54 53 } 55 54 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/Test.java
r5583 r6388 142 142 checkEnabled = new JCheckBox(name, enabled); 143 143 checkEnabled.setToolTipText(description); 144 checkEnabled.addActionListener(new ActionListener(){145 public void actionPerformed(ActionEvent e) {146 setGuiEnabled(checkEnabled.isSelected() || checkBeforeUpload.isSelected() );147 }148 });149 144 testPanel.add(checkEnabled, GBC.std().insets(20,0,0,0)); 150 145 151 146 checkBeforeUpload = new JCheckBox(); 152 147 checkBeforeUpload.setSelected(testBeforeUpload); 153 checkBeforeUpload.addActionListener(new ActionListener(){154 public void actionPerformed(ActionEvent e) {155 setGuiEnabled(checkEnabled.isSelected() || checkBeforeUpload.isSelected() );156 }157 });158 148 testPanel.add(checkBeforeUpload, GBC.eop().insets(20,0,0,0)); 159 149 } 160 161 /**162 * Enables or disables the test in the preferences gui163 * @param enabled164 */165 public void setGuiEnabled(boolean enabled)166 {167 }168 150 169 151 /** -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java
r4087 r6388 58 58 return; 59 59 60 Collection<Test> tests = OSMValidatorPlugin.get Tests(true,false);60 Collection<Test> tests = OSMValidatorPlugin.getEnabledTests(false); 61 61 if( tests.isEmpty() ) 62 62 return; -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateUploadHook.java
r4087 r6388 32 32 public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) 33 33 { 34 Collection<Test> tests = OSMValidatorPlugin.get Tests(false,true);34 Collection<Test> tests = OSMValidatorPlugin.getEnabledTests(true); 35 35 if( tests.isEmpty() ) 36 36 return true; … … 43 43 for(Test test : tests) 44 44 { 45 if( !test.testBeforeUpload() )46 continue;47 48 45 test.setBeforeUpload(true); 49 46 test.setPartialSelection(true);
Note:
See TracChangeset
for help on using the changeset viewer.