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