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

Last change on this file since 6362 was 6362, checked in by Don-vip, 10 years ago

Checkstyle:

  • private constructors for util classes
  • final classes
  • missing "else" statements
  • import cleanup
  • 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.awt.event.ActionEvent;
8import java.awt.event.ActionListener;
9import java.util.Collection;
10
11import javax.swing.BorderFactory;
12import javax.swing.JCheckBox;
13import javax.swing.JLabel;
14import javax.swing.JPanel;
15
16import org.openstreetmap.josm.Main;
17import org.openstreetmap.josm.data.validation.OsmValidator;
18import org.openstreetmap.josm.data.validation.Test;
19import org.openstreetmap.josm.tools.GBC;
20
21/**
22 * Preference settings for the validator
23 *
24 * @author frsantos
25 */
26public final 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 @Override
99 public void actionPerformed(ActionEvent e) {
100 prefOtherUpload.setEnabled(prefOther.isSelected());
101 }
102 };
103 prefOther.addActionListener(otherUploadEnabled);
104 otherUploadEnabled.actionPerformed(null);
105
106 GBC a = GBC.eol().insets(-5,0,0,0);
107 a.anchor = GBC.EAST;
108 testPanel.add( new JLabel(tr("On demand")), GBC.std() );
109 testPanel.add( new JLabel(tr("On upload")), a );
110
111 allTests = OsmValidator.getTests();
112 for (Test test: allTests) {
113 test.addGui(testPanel);
114 }
115
116 createPreferenceTabWithScrollPane(gui, testPanel);
117 }
118
119 @Override
120 public boolean ok() {
121 StringBuilder tests = new StringBuilder();
122 StringBuilder testsBeforeUpload = new StringBuilder();
123
124 for (Test test : allTests) {
125 test.ok();
126 String name = test.getClass().getSimpleName();
127 tests.append(',').append(name).append('=').append(test.enabled);
128 testsBeforeUpload.append(',').append(name).append('=').append(test.testBeforeUpload);
129 }
130
131 if (tests.length() > 0) {
132 tests = tests.deleteCharAt(0);
133 }
134 if (testsBeforeUpload.length() > 0) {
135 testsBeforeUpload = testsBeforeUpload.deleteCharAt(0);
136 }
137
138 OsmValidator.initializeTests(allTests);
139
140 Main.pref.put(PREF_TESTS, tests.toString());
141 Main.pref.put(PREF_TESTS_BEFORE_UPLOAD, testsBeforeUpload.toString());
142 Main.pref.put(PREF_USE_IGNORE, prefUseIgnore.isSelected());
143 Main.pref.put(PREF_OTHER, prefOther.isSelected());
144 Main.pref.put(PREF_OTHER_UPLOAD, prefOtherUpload.isSelected());
145 Main.pref.put(PREF_LAYER, prefUseLayer.isSelected());
146 return false;
147 }
148}
Note: See TracBrowser for help on using the repository browser.