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