Changeset 16832 in josm


Ignore:
Timestamp:
2020-08-03T19:46:04+02:00 (4 years ago)
Author:
simon04
Message:

fix #18899 - OpeningHoursParser: allow to specify strictness in preferences

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java

    r16244 r16832  
    1212import java.util.Objects;
    1313
     14import javax.swing.JCheckBox;
     15import javax.swing.JPanel;
     16
    1417import ch.poole.openinghoursparser.OpeningHoursParser;
    1518import ch.poole.openinghoursparser.ParseException;
     
    1821import org.openstreetmap.josm.command.ChangePropertyCommand;
    1922import org.openstreetmap.josm.data.osm.OsmPrimitive;
     23import org.openstreetmap.josm.data.preferences.BooleanProperty;
     24import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
    2025import org.openstreetmap.josm.data.validation.Severity;
    2126import org.openstreetmap.josm.data.validation.Test.TagTest;
    2227import org.openstreetmap.josm.data.validation.TestError;
     28import org.openstreetmap.josm.tools.GBC;
    2329
    2430/**
     
    3238
    3339    private static final Collection<String> KEYS_TO_CHECK = Arrays.asList("opening_hours", "collection_times", "service_times");
     40    private static final BooleanProperty PREF_STRICT_MODE =
     41            new BooleanProperty(ValidatorPrefHelper.PREFIX + "." + OpeningHourTest.class.getSimpleName() + "." + "strict", false);
     42    private final JCheckBox checkboxStrictMode = new JCheckBox(tr("Enable strict mode."));
    3443
    3544    /**
     
    9099        String prettifiedValue = null;
    91100        try {
    92             final List<Rule> rules = new OpeningHoursParser(new StringReader(value)).rules(false);
     101            final boolean strict = PREF_STRICT_MODE.get();
     102            final List<Rule> rules = new OpeningHoursParser(new StringReader(value)).rules(strict);
    93103            prettifiedValue = Util.rulesToOpeningHoursString(rules);
    94             if (!Objects.equals(value, prettifiedValue)) {
     104            if (!Objects.equals(value, prettifiedValue) && !strict) {
    95105                // parse again in strict mode for detailed message
    96106                new OpeningHoursParser(new StringReader(value)).rules(true);
     
    121131        }
    122132    }
     133
     134    @Override
     135    public void addGui(JPanel testPanel) {
     136        super.addGui(testPanel);
     137        checkboxStrictMode.setSelected(PREF_STRICT_MODE.get());
     138        testPanel.add(checkboxStrictMode, GBC.eol().insets(20, 0, 0, 0));
     139    }
     140
     141    @Override
     142    public boolean ok() {
     143        super.ok();
     144        PREF_STRICT_MODE.put(checkboxStrictMode.isSelected());
     145        return false;
     146    }
    123147}
Note: See TracChangeset for help on using the changeset viewer.