[7937] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.preferences.validator;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.GridBagLayout;
|
---|
| 7 | import java.awt.event.ActionListener;
|
---|
| 8 | import java.util.ArrayList;
|
---|
| 9 | import java.util.Collection;
|
---|
| 10 | import java.util.LinkedList;
|
---|
| 11 | import java.util.List;
|
---|
| 12 |
|
---|
| 13 | import javax.swing.BorderFactory;
|
---|
| 14 | import javax.swing.JCheckBox;
|
---|
| 15 | import javax.swing.JLabel;
|
---|
| 16 | import javax.swing.JPanel;
|
---|
| 17 |
|
---|
| 18 | import org.openstreetmap.josm.Main;
|
---|
[12649] | 19 | import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
|
---|
[7937] | 20 | import org.openstreetmap.josm.data.validation.OsmValidator;
|
---|
| 21 | import org.openstreetmap.josm.data.validation.Test;
|
---|
| 22 | import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
|
---|
| 23 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
| 24 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
---|
| 25 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
| 26 | import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
|
---|
| 27 | import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
|
---|
| 28 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
[9778] | 29 | import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
|
---|
[7937] | 30 | import org.openstreetmap.josm.tools.GBC;
|
---|
| 31 |
|
---|
| 32 | /**
|
---|
| 33 | * The general validator preferences, allowing to enable/disable tests.
|
---|
| 34 | * @since 6666
|
---|
| 35 | */
|
---|
| 36 | public class ValidatorTestsPreference implements SubPreferenceSetting {
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * Factory used to create a new {@code ValidatorTestsPreference}.
|
---|
| 40 | */
|
---|
| 41 | public static class Factory implements PreferenceSettingFactory {
|
---|
| 42 | @Override
|
---|
| 43 | public PreferenceSetting createPreferenceSetting() {
|
---|
| 44 | return new ValidatorTestsPreference();
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | private JCheckBox prefUseIgnore;
|
---|
| 49 | private JCheckBox prefUseLayer;
|
---|
| 50 | private JCheckBox prefOtherUpload;
|
---|
| 51 | private JCheckBox prefOther;
|
---|
| 52 |
|
---|
| 53 | /** The list of all tests */
|
---|
| 54 | private Collection<Test> allTests;
|
---|
| 55 |
|
---|
| 56 | @Override
|
---|
| 57 | public void addGui(PreferenceTabbedPane gui) {
|
---|
[9778] | 58 | JPanel testPanel = new VerticallyScrollablePanel(new GridBagLayout());
|
---|
[8510] | 59 | testPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
---|
[7937] | 60 |
|
---|
[12649] | 61 | prefUseIgnore = new JCheckBox(tr("Use ignore list."), ValidatorPrefHelper.PREF_USE_IGNORE.get());
|
---|
[7937] | 62 | prefUseIgnore.setToolTipText(tr("Use the ignore list to suppress warnings."));
|
---|
| 63 | testPanel.add(prefUseIgnore, GBC.eol());
|
---|
| 64 |
|
---|
[12649] | 65 | prefUseLayer = new JCheckBox(tr("Use error layer."), ValidatorPrefHelper.PREF_LAYER.get());
|
---|
[7937] | 66 | prefUseLayer.setToolTipText(tr("Use the error layer to display problematic elements."));
|
---|
| 67 | testPanel.add(prefUseLayer, GBC.eol());
|
---|
| 68 |
|
---|
[12649] | 69 | prefOther = new JCheckBox(tr("Show informational level."), ValidatorPrefHelper.PREF_OTHER.get());
|
---|
[7937] | 70 | prefOther.setToolTipText(tr("Show the informational tests."));
|
---|
| 71 | testPanel.add(prefOther, GBC.eol());
|
---|
| 72 |
|
---|
[8509] | 73 | prefOtherUpload = new JCheckBox(tr("Show informational level on upload."),
|
---|
[12649] | 74 | ValidatorPrefHelper.PREF_OTHER_UPLOAD.get());
|
---|
[7937] | 75 | prefOtherUpload.setToolTipText(tr("Show the informational tests in the upload check windows."));
|
---|
| 76 | testPanel.add(prefOtherUpload, GBC.eol());
|
---|
| 77 |
|
---|
[10611] | 78 | ActionListener otherUploadEnabled = e -> prefOtherUpload.setEnabled(prefOther.isSelected());
|
---|
[7937] | 79 | prefOther.addActionListener(otherUploadEnabled);
|
---|
| 80 | otherUploadEnabled.actionPerformed(null);
|
---|
| 81 |
|
---|
[8510] | 82 | GBC a = GBC.eol().insets(-5, 0, 0, 0);
|
---|
[7937] | 83 | a.anchor = GBC.EAST;
|
---|
[8444] | 84 | testPanel.add(new JLabel(tr("On demand")), GBC.std());
|
---|
| 85 | testPanel.add(new JLabel(tr("On upload")), a);
|
---|
[7937] | 86 |
|
---|
| 87 | allTests = OsmValidator.getTests();
|
---|
| 88 | for (Test test: allTests) {
|
---|
| 89 | test.addGui(testPanel);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | gui.getValidatorPreference().addSubTab(this, tr("Tests"),
|
---|
| 93 | GuiHelper.embedInVerticalScrollPane(testPanel),
|
---|
| 94 | tr("Choose tests to enable"));
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | @Override
|
---|
| 98 | public boolean ok() {
|
---|
[12841] | 99 | List<String> tests = new LinkedList<>();
|
---|
| 100 | List<String> testsBeforeUpload = new LinkedList<>();
|
---|
[7937] | 101 |
|
---|
| 102 | for (Test test : allTests) {
|
---|
| 103 | test.ok();
|
---|
| 104 | String name = test.getClass().getName();
|
---|
[8510] | 105 | if (!test.enabled)
|
---|
[7937] | 106 | tests.add(name);
|
---|
[8510] | 107 | if (!test.testBeforeUpload)
|
---|
[7937] | 108 | testsBeforeUpload.add(name);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | // Initializes all tests but MapCSSTagChecker because it is initialized
|
---|
| 112 | // later in ValidatorTagCheckerRulesPreference.ok(),
|
---|
| 113 | // after its list of rules has been saved to preferences
|
---|
| 114 | List<Test> testsToInitialize = new ArrayList<>(allTests);
|
---|
| 115 | testsToInitialize.remove(OsmValidator.getTest(MapCSSTagChecker.class));
|
---|
| 116 | OsmValidator.initializeTests(testsToInitialize);
|
---|
| 117 |
|
---|
[12841] | 118 | Main.pref.putList(ValidatorPrefHelper.PREF_SKIP_TESTS, tests);
|
---|
| 119 | Main.pref.putList(ValidatorPrefHelper.PREF_SKIP_TESTS_BEFORE_UPLOAD, testsBeforeUpload);
|
---|
[12649] | 120 | ValidatorPrefHelper.PREF_USE_IGNORE.put(prefUseIgnore.isSelected());
|
---|
| 121 | ValidatorPrefHelper.PREF_OTHER.put(prefOther.isSelected());
|
---|
| 122 | ValidatorPrefHelper.PREF_OTHER_UPLOAD.put(prefOtherUpload.isSelected());
|
---|
| 123 | ValidatorPrefHelper.PREF_LAYER.put(prefUseLayer.isSelected());
|
---|
[7937] | 124 | return false;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | @Override
|
---|
| 128 | public boolean isExpert() {
|
---|
| 129 | return false;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | @Override
|
---|
| 133 | public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) {
|
---|
| 134 | return gui.getValidatorPreference();
|
---|
| 135 | }
|
---|
| 136 | }
|
---|