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

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

fix #7386 - Major rework of preferences GUI settings in order to speed up preferences dialog startup time. The building of each preferences tab is delayed until this tab is selected. Plugins that use preferences will need to make some (minor) changes.

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