source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/ValidatorPreference.java@ 3723

Last change on this file since 3723 was 3723, checked in by stoecker, 13 years ago

default disable validator info warnings also for manual tests

  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.gui.preferences;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7import java.util.Collection;
8
9import javax.swing.BorderFactory;
10import javax.swing.JCheckBox;
11import javax.swing.JLabel;
12import javax.swing.JPanel;
13import javax.swing.JScrollPane;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.data.validation.OsmValidator;
17import org.openstreetmap.josm.data.validation.Test;
18import org.openstreetmap.josm.tools.GBC;
19
20/**
21 * Preference settings for the validator
22 *
23 * @author frsantos
24 */
25public class ValidatorPreference implements PreferenceSetting {
26
27 public static class Factory implements PreferenceSettingFactory {
28 @Override
29 public PreferenceSetting createPreferenceSetting() {
30 return new ValidatorPreference();
31 }
32 }
33
34 /** The preferences prefix */
35 public static final String PREFIX = "validator";
36
37 /** The preferences key for debug preferences */
38 public static final String PREF_DEBUG = PREFIX + ".debug";
39
40 /** The preferences key for debug preferences */
41 public static final String PREF_LAYER = PREFIX + ".layer";
42
43 /** The preferences key for enabled tests */
44 public static final String PREF_TESTS = PREFIX + ".tests";
45
46 /** The preferences key for enabled tests */
47 public static final String PREF_USE_IGNORE = PREFIX + ".ignore";
48
49 /** The preferences key for enabled tests before upload*/
50 public static final String PREF_TESTS_BEFORE_UPLOAD = PREFIX + ".testsBeforeUpload";
51
52 /** The preferences key for ignored severity other on upload */
53 public static final String PREF_OTHER_UPLOAD = PREFIX + ".otherUpload";
54
55 /** The preferences key for ignored severity other */
56 public static final String PREF_OTHER = PREFIX + ".other";
57
58 /**
59 * The preferences key for enabling the permanent filtering
60 * of the displayed errors in the tree regarding the current selection
61 */
62 public static final String PREF_FILTER_BY_SELECTION = PREFIX + ".selectionFilter";
63
64 private JCheckBox prefUseIgnore;
65 private JCheckBox prefUseLayer;
66 private JCheckBox prefOtherUpload;
67 private JCheckBox prefOther;
68
69 /** The list of all tests */
70 private Collection<Test> allTests;
71
72 @Override
73 public void addGui(PreferenceTabbedPane gui)
74 {
75 JPanel testPanel = new JPanel(new GridBagLayout());
76 testPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
77
78 prefUseIgnore = new JCheckBox(tr("Use ignore list."), Main.pref.getBoolean(PREF_USE_IGNORE, true));
79 prefUseIgnore.setToolTipText(tr("Use the ignore list to suppress warnings."));
80 testPanel.add(prefUseIgnore, GBC.eol());
81
82 prefUseLayer = new JCheckBox(tr("Use error layer."), Main.pref.getBoolean(PREF_LAYER, true));
83 prefUseLayer.setToolTipText(tr("Use the error layer to display problematic elements."));
84 testPanel.add(prefUseLayer, GBC.eol());
85
86 prefOther = new JCheckBox(tr("Show informational level."), Main.pref.getBoolean(PREF_OTHER, false));
87 prefOther.setToolTipText(tr("Show the informational tests."));
88 testPanel.add(prefOther, GBC.eol());
89
90 prefOtherUpload = new JCheckBox(tr("Show informational level on upload."), Main.pref.getBoolean(PREF_OTHER_UPLOAD, false));
91 prefOtherUpload.setToolTipText(tr("Show the informational tests in the upload check windows."));
92 testPanel.add(prefOtherUpload, GBC.eol());
93
94 GBC a = GBC.eol().insets(-5,0,0,0);
95 a.anchor = GBC.EAST;
96 testPanel.add( new JLabel(tr("On demand")), GBC.std() );
97 testPanel.add( new JLabel(tr("On upload")), a );
98
99 allTests = OsmValidator.getTests();
100 for (Test test: allTests) {
101 test.addGui(testPanel);
102 }
103
104 JScrollPane testPane = new JScrollPane(testPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
105 testPane.setBorder(null);
106
107 String description = tr("An OSM data validator that checks for common errors made by users and editor programs.");
108 JPanel tab = gui.createPreferenceTab("validator", tr("Data validator"), description);
109 tab.add(testPane, GBC.eol().fill(GBC.BOTH));
110 tab.add(GBC.glue(0,10), a);
111 }
112
113 @Override
114 public boolean ok() {
115 StringBuilder tests = new StringBuilder();
116 StringBuilder testsBeforeUpload = new StringBuilder();
117
118 for (Test test : allTests) {
119 String name = test.getClass().getSimpleName();
120 tests.append(',').append(name).append('=').append(test.enabled);
121 testsBeforeUpload.append(',').append(name).append('=').append(test.testBeforeUpload);
122 }
123
124 if (tests.length() > 0) {
125 tests = tests.deleteCharAt(0);
126 }
127 if (testsBeforeUpload.length() > 0) {
128 testsBeforeUpload = testsBeforeUpload.deleteCharAt(0);
129 }
130
131 OsmValidator.initializeTests(allTests);
132
133 Main.pref.put(PREF_TESTS, tests.toString());
134 Main.pref.put(PREF_TESTS_BEFORE_UPLOAD, testsBeforeUpload.toString());
135 Main.pref.put(PREF_USE_IGNORE, prefUseIgnore.isSelected());
136 Main.pref.put(PREF_OTHER, prefOther.isSelected());
137 Main.pref.put(PREF_OTHER_UPLOAD, prefOtherUpload.isSelected());
138 Main.pref.put(PREF_LAYER, prefUseLayer.isSelected());
139 return false;
140 }
141}
Note: See TracBrowser for help on using the repository browser.