Changeset 6670 in josm for trunk/src/org


Ignore:
Timestamp:
2014-01-11T02:21:08+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9508 - Centralized service for validator rules

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r6656 r6670  
    15821582                "validator.TagChecker.useignorefile",          // 01/2014 - can be removed mid-2014. Replaced by validator.TagChecker.source
    15831583                "validator.TagChecker.usespellfile",           // 01/2014 - can be removed mid-2014. Replaced by validator.TagChecker.source
     1584                "validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.sources" // 01/2014 - can be removed mid-2014. Replaced by validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries
    15841585        };
    15851586        for (String key : obsolete) {
  • trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java

    r6669 r6670  
    9191
    9292    /**
    93      * Replies true if east and north are different from Double.NaN and not inifinite
     93     * Replies true if east and north are different from Double.NaN and not infinite
    9494     *
    95      * @return true if east and north are different from Double.NaN and not inifinite
     95     * @return true if east and north are different from Double.NaN and not infinite
    9696     */
    9797    public boolean isValid() {
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r6648 r6670  
    222222        return new HashMap<String, Test>(allTestsMap);
    223223    }
     224   
     225    /**
     226     * Returns the instance of the given test class.
     227     * @param testClass The class of test to retrieve
     228     * @return the instance of the given test class, if any, or {@code null}
     229     * @since 6670
     230     */
     231    @SuppressWarnings("unchecked")
     232    public static <T extends Test> T getTest(Class<T> testClass) {
     233        if (testClass == null) {
     234            return null;
     235        }
     236        return (T) allTestsMap.get(testClass.getSimpleName());
     237    }
    224238
    225239    private static void applyPrefs(Map<String, Test> tests, boolean beforeUpload) {
     
    283297     * @param allTests The tests to initialize
    284298     */
    285     public static void initializeTests(Collection<Test> allTests) {
     299    public static void initializeTests(Collection<? extends Test> allTests) {
    286300        for (Test test : allTests) {
    287301            try {
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r6651 r6670  
    55
    66import java.io.BufferedReader;
    7 import java.io.InputStreamReader;
     7import java.io.IOException;
    88import java.io.Reader;
    99import java.util.ArrayList;
    1010import java.util.Collection;
    11 import java.util.Collections;
    1211import java.util.HashMap;
     12import java.util.Iterator;
    1313import java.util.LinkedHashMap;
    1414import java.util.LinkedList;
     
    2525import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2626import org.openstreetmap.josm.data.osm.Tag;
    27 import org.openstreetmap.josm.data.preferences.CollectionProperty;
    2827import org.openstreetmap.josm.data.validation.FixableTestError;
    2928import org.openstreetmap.josm.data.validation.Severity;
     
    3837import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    3938import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
     39import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
    4040import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser;
    4141import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
    4242import org.openstreetmap.josm.gui.preferences.validator.ValidatorPreference;
    43 import org.openstreetmap.josm.gui.widgets.EditableList;
     43import org.openstreetmap.josm.gui.preferences.validator.ValidatorTagCheckerRulesPreference;
    4444import org.openstreetmap.josm.io.MirroredInputStream;
    4545import org.openstreetmap.josm.io.UTFInputStreamReader;
    4646import org.openstreetmap.josm.tools.CheckParameterUtil;
    47 import org.openstreetmap.josm.tools.GBC;
    4847import org.openstreetmap.josm.tools.Predicate;
    4948import org.openstreetmap.josm.tools.Utils;
    50 
    51 import javax.swing.JLabel;
    52 import javax.swing.JPanel;
    5349
    5450/**
     
    5753 */
    5854public class MapCSSTagChecker extends Test.TagTest {
     55
     56    /**
     57     * The preference key for tag checker source entries.
     58     * @since 6670
     59     */
     60    public static final String ENTRIES_PREF_KEY = "validator." + MapCSSTagChecker.class.getName() + ".entries";
    5961
    6062    /**
     
    170172            css.sheet(source);
    171173            assert source.getErrors().isEmpty();
     174            // Ignore "meta" rule(s) from external rules of JOSM wiki
     175            removeMetaRules(source);
    172176            return new ArrayList<TagCheck>(Utils.transform(source.rules, new Utils.Function<MapCSSRule, TagCheck>() {
    173177                @Override
     
    176180                }
    177181            }));
     182        }
     183       
     184        private static void removeMetaRules(MapCSSStyleSource source) {
     185            for (Iterator<MapCSSRule> it = source.rules.iterator(); it.hasNext(); ) {
     186                MapCSSRule x = it.next();
     187                if (x.selectors.size() == 1) {
     188                    Selector sel = x.selectors.get(0);
     189                    if (sel instanceof GeneralSelector) {
     190                        GeneralSelector gs = (GeneralSelector) sel;
     191                        if ("meta".equals(gs.base) && gs.getConditions().isEmpty()) {
     192                            it.remove();
     193                        }
     194                    }
     195                }
     196            }
    178197        }
    179198
     
    405424    }
    406425
    407     /**
    408      * Adds a new MapCSS config file from the given internal filename.
    409      * @param internalConfigFile the filename in data/validator
    410      * @throws ParseException if the config file does not match MapCSS syntax
    411      */
    412     private void addMapCSS(String internalConfigFile) throws ParseException {
    413         addMapCSS(new InputStreamReader(getClass().getResourceAsStream("/data/validator/" + internalConfigFile + ".mapcss"), Utils.UTF_8));
    414     }
    415 
    416426    @Override
    417427    public synchronized void initialize() throws Exception {
    418428        checks.clear();
    419         addMapCSS("deprecated");
    420         addMapCSS("highway");
    421         addMapCSS("numeric");
    422         addMapCSS("religion");
    423         addMapCSS("relation");
    424         addMapCSS("combinations");
    425         addMapCSS("unnecessary");
    426         addMapCSS("wikipedia");
    427         addMapCSS("power");
    428         addMapCSS("geometry");
    429         for (final String i : sourcesProperty.get()) {
     429        for (String i : new ValidatorTagCheckerRulesPreference.RulePrefHelper().getActiveUrls()) {
    430430            try {
    431431                Main.info(tr("Adding {0} to tag checker", i));
    432                 addMapCSS(new BufferedReader(UTFInputStreamReader.create(new MirroredInputStream(i))));
     432                MirroredInputStream s = new MirroredInputStream(i);
     433                try {
     434                    addMapCSS(new BufferedReader(UTFInputStreamReader.create(s)));
     435                } finally {
     436                    Utils.close(s);
     437                }
     438            } catch (IOException ex) {
     439                Main.warn(tr("Failed to add {0} to tag checker", i));
     440                Main.warn(ex, false);
    433441            } catch (Exception ex) {
    434                 Main.warn(new RuntimeException(tr("Failed to add {0} to tag checker", i), ex));
    435             }
    436         }
    437     }
    438 
    439     protected EditableList sourcesList;
    440     protected final CollectionProperty sourcesProperty = new CollectionProperty(
    441             "validator." + this.getClass().getName() + ".sources", Collections.<String>emptyList());
    442 
    443     @Override
    444     public void addGui(JPanel testPanel) {
    445         super.addGui(testPanel);
    446         sourcesList = new EditableList(tr("TagChecker source"));
    447         sourcesList.setItems(sourcesProperty.get());
    448         testPanel.add(new JLabel(tr("Data sources ({0})", "*.validator.mapcss")), GBC.eol().insets(23, 0, 0, 0));
    449         testPanel.add(sourcesList, GBC.eol().fill(GBC.HORIZONTAL).insets(23, 0, 0, 0));
    450     }
    451 
    452     @Override
    453     public boolean ok() {
    454         sourcesProperty.put(sourcesList.getItems());
    455         return super.ok();
     442                Main.warn(tr("Failed to add {0} to tag checker", i));
     443                Main.warn(ex);
     444            }
     445        }
    456446    }
    457447}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r6643 r6670  
    4242    private static ElemStyles styles = new ElemStyles();
    4343
     44    /**
     45     * Returns the {@link ElemStyles} instance.
     46     * @return the {@code ElemStyles} instance
     47     */
    4448    public static ElemStyles getStyles() {
    4549        return styles;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r6643 r6670  
    3434
    3535public class MapCSSStyleSource extends StyleSource {
    36     final public List<MapCSSRule> rules;
     36    public final List<MapCSSRule> rules;
    3737    private Color backgroundColorOverride;
    3838    private String css = null;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r6623 r6670  
    346346
    347347        public List<Condition> getConditions() {
     348            if (conds == null) {
     349                return Collections.emptyList();
     350            }
    348351            return Collections.unmodifiableList(conds);
    349352        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r6666 r6670  
    5353import org.openstreetmap.josm.gui.preferences.shortcut.ShortcutPreference;
    5454import org.openstreetmap.josm.gui.preferences.validator.ValidatorPreference;
     55import org.openstreetmap.josm.gui.preferences.validator.ValidatorTagCheckerRulesPreference;
    5556import org.openstreetmap.josm.gui.preferences.validator.ValidatorTestsPreference;
    5657import org.openstreetmap.josm.plugins.PluginDownloadTask;
     
    514515        settingsFactory.add(new ValidatorPreference.Factory());
    515516        settingsFactory.add(new ValidatorTestsPreference.Factory());
     517        settingsFactory.add(new ValidatorTagCheckerRulesPreference.Factory());
    516518        settingsFactory.add(new RemoteControlPreference.Factory());
    517519        settingsFactory.add(new ImageryPreference.Factory());
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r6552 r6670  
    3333import java.util.EventObject;
    3434import java.util.HashMap;
     35import java.util.HashSet;
    3536import java.util.Iterator;
    3637import java.util.List;
    3738import java.util.Map;
     39import java.util.Set;
    3840import java.util.concurrent.CopyOnWriteArrayList;
    3941import java.util.regex.Matcher;
     
    6466import javax.swing.event.CellEditorListener;
    6567import javax.swing.event.ChangeEvent;
     68import javax.swing.event.ChangeListener;
    6669import javax.swing.event.ListSelectionEvent;
    6770import javax.swing.event.ListSelectionListener;
     
    9396public abstract class SourceEditor extends JPanel {
    9497
    95     final protected boolean isMapPaint;
     98    protected final SourceType sourceType;
     99    protected final boolean canEnable;
    96100
    97101    protected final JTable tblActiveSources;
     
    99103    protected final JList lstAvailableSources;
    100104    protected final AvailableSourcesListModel availableSourcesModel;
    101     protected final JTable tblIconPaths;
    102     protected final IconPathTableModel iconPathsModel;
    103105    protected final String availableSourcesUrl;
    104106    protected final List<SourceProvider> sourceProviders;
    105107
     108    protected JTable tblIconPaths;
     109    protected IconPathTableModel iconPathsModel;
     110
    106111    protected boolean sourcesInitiallyLoaded;
    107112
    108113    /**
    109      * constructor
    110      * @param isMapPaint true for MapPaintPreference subclass, false
    111      *  for TaggingPresetPreference subclass
     114     * Constructs a new {@code SourceEditor}.
     115     * @param sourceType the type of source managed by this editor
    112116     * @param availableSourcesUrl the URL to the list of available sources
    113117     * @param sourceProviders the list of additional source providers, from plugins
     118     * @param handleIcons {@code true} if icons may be managed, {@code false} otherwise
    114119     */
    115     public SourceEditor(final boolean isMapPaint, final String availableSourcesUrl, final List<SourceProvider> sourceProviders) {
    116 
    117         this.isMapPaint = isMapPaint;
     120    public SourceEditor(SourceType sourceType, String availableSourcesUrl, List<SourceProvider> sourceProviders, boolean handleIcons) {
     121
     122        this.sourceType = sourceType;
     123        this.canEnable = sourceType.equals(SourceType.MAP_PAINT_STYLE) || sourceType.equals(SourceType.TAGCHECKER_RULE);
     124       
    118125        DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    119         this.lstAvailableSources = new JList(availableSourcesModel = new AvailableSourcesListModel(selectionModel));
     126        this.availableSourcesModel = new AvailableSourcesListModel(selectionModel);
     127        this.lstAvailableSources = new JList(availableSourcesModel);
    120128        this.lstAvailableSources.setSelectionModel(selectionModel);
    121129        this.lstAvailableSources.setCellRenderer(new SourceEntryListCellRenderer());
     
    124132
    125133        selectionModel = new DefaultListSelectionModel();
    126         tblActiveSources = new JTable(activeSourcesModel = new ActiveSourcesModel(selectionModel)) {
     134        activeSourcesModel = new ActiveSourcesModel(selectionModel);
     135        tblActiveSources = new JTable(activeSourcesModel) {
    127136            // some kind of hack to prevent the table from scrolling slightly to the
    128137            // right when clicking on the text
     
    140149        tblActiveSources.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    141150        SourceEntryTableCellRenderer sourceEntryRenderer = new SourceEntryTableCellRenderer();
    142         if (isMapPaint) {
     151        if (canEnable) {
    143152            tblActiveSources.getColumnModel().getColumn(0).setMaxWidth(1);
    144153            tblActiveSources.getColumnModel().getColumn(0).setResizable(false);
     
    153162            @Override
    154163            public void tableChanged(TableModelEvent e) {
    155                 TableHelper.adjustColumnWidth(tblActiveSources, isMapPaint ? 1 : 0, 800);
     164                TableHelper.adjustColumnWidth(tblActiveSources, canEnable ? 1 : 0, 800);
    156165            }
    157166        });
     
    168177                    if (row < 0 || row >= tblActiveSources.getRowCount())
    169178                        return;
    170                     if (isMapPaint && col != 1)
     179                    if (canEnable && col != 1)
    171180                        return;
    172181                    editActiveSourceAction.actionPerformed(null);
     
    182191        MoveUpDownAction moveUp = null;
    183192        MoveUpDownAction moveDown = null;
    184         if (isMapPaint) {
     193        if (sourceType.equals(SourceType.MAP_PAINT_STYLE)) {
    185194            moveUp = new MoveUpDownAction(false);
    186195            moveDown = new MoveUpDownAction(true);
     
    259268        sideButtonTB.add(removeActiveSourcesAction);
    260269        sideButtonTB.addSeparator(new Dimension(12, 30));
    261         if (isMapPaint) {
     270        if (sourceType.equals(SourceType.MAP_PAINT_STYLE)) {
    262271            sideButtonTB.add(moveUp);
    263272            sideButtonTB.add(moveDown);
     
    297306         **/
    298307
    299         selectionModel = new DefaultListSelectionModel();
    300         tblIconPaths = new JTable(iconPathsModel = new IconPathTableModel(selectionModel));
     308        if (handleIcons) {
     309            buildIcons(gbc);
     310        }
     311    }
     312
     313    private void buildIcons(GridBagConstraints gbc) {
     314        DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
     315        iconPathsModel = new IconPathTableModel(selectionModel);
     316        tblIconPaths = new JTable(iconPathsModel);
    301317        tblIconPaths.setSelectionModel(selectionModel);
    302318        tblIconPaths.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     
    334350        gbc.insets = new Insets(0, 11, 0, 0);
    335351
    336         add(sp = new JScrollPane(tblIconPaths), gbc);
     352        JScrollPane sp = new JScrollPane(tblIconPaths);
     353        add(sp, gbc);
    337354        sp.setColumnHeaderView(null);
    338355
     
    485502        @Override
    486503        public int getColumnCount() {
    487             return isMapPaint ? 2 : 1;
     504            return canEnable ? 2 : 1;
    488505        }
    489506
     
    495512        @Override
    496513        public Object getValueAt(int rowIndex, int columnIndex) {
    497             if (isMapPaint && columnIndex == 0)
     514            if (canEnable && columnIndex == 0)
    498515                return data.get(rowIndex).active;
    499516            else
     
    503520        @Override
    504521        public boolean isCellEditable(int rowIndex, int columnIndex) {
    505             return isMapPaint && columnIndex == 0;
     522            return canEnable && columnIndex == 0;
    506523        }
    507524
    508525        @Override
    509526        public Class<?> getColumnClass(int column) {
    510             if (isMapPaint && column == 0)
     527            if (canEnable && column == 0)
    511528                return Boolean.class;
    512529            else return SourceEntry.class;
     
    517534            if (row < 0 || row >= getRowCount() || aValue == null)
    518535                return;
    519             if (isMapPaint && column == 0) {
     536            if (canEnable && column == 0) {
    520537                data.get(row).active = ! data.get(row).active;
    521538            }
     
    709726            }
    710727
    711             if (isMapPaint) {
     728            if (canEnable) {
    712729                cbActive = new JCheckBox(tr("active"), e != null ? e.active : true);
    713730                p.add(cbActive, GBC.eol().insets(15, 0, 5, 0));
     
    752769            public void actionPerformed(ActionEvent e) {
    753770                FileFilter ff;
    754                 if (isMapPaint) {
     771                switch (sourceType) {
     772                case MAP_PAINT_STYLE:
    755773                    ff = new ExtensionFileFilter("xml,mapcss,css,zip", "xml", tr("Map paint style file (*.xml, *.mapcss, *.zip)"));
    756                 } else {
     774                    break;
     775                case TAGGING_PRESET:
    757776                    ff = new ExtensionFileFilter("xml,zip", "xml", tr("Preset definition file (*.xml, *.zip)"));
     777                    break;
     778                case TAGCHECKER_RULE:
     779                    ff = new ExtensionFileFilter("validator.mapcss,zip", "validator.mapcss", tr("Tag checker rule (*.validator.mapcss, *.zip)"));
     780                    break;
     781                default:
     782                    Main.error("Unsupported source type: "+sourceType);
     783                    return;
    758784                }
    759785                JFileChooserManager fcm = new JFileChooserManager(true)
     
    777803
    778804        public boolean active() {
    779             if (!isMapPaint)
     805            if (!canEnable)
    780806                throw new UnsupportedOperationException();
    781807            return cbActive.isSelected();
     
    799825            if (editEntryDialog.getValue() == 1) {
    800826                boolean active = true;
    801                 if (isMapPaint) {
     827                if (canEnable) {
    802828                    active = editEntryDialog.active();
    803829                }
     
    870896                }
    871897                e.url = editEntryDialog.getURL();
    872                 if (isMapPaint) {
     898                if (canEnable) {
    873899                    e.active = editEntryDialog.active();
    874900                }
     
    14951521        private final String pref;
    14961522
     1523        /**
     1524         * Constructs a new {@code SourcePrefHelper} for the given preference key.
     1525         * @param pref The preference key
     1526         */
    14971527        public SourcePrefHelper(String pref) {
    14981528            this.pref = pref;
    14991529        }
    15001530
     1531        /**
     1532         * Returns the default sources provided by JOSM core.
     1533         * @return the default sources provided by JOSM core
     1534         */
    15011535        abstract public Collection<ExtendedSourceEntry> getDefault();
    15021536
     
    15051539        abstract public SourceEntry deserialize(Map<String, String> entryStr);
    15061540
     1541        /**
     1542         * Returns the list of sources.
     1543         * @return The list of sources
     1544         */
    15071545        public List<SourceEntry> get() {
    15081546
     
    15281566            return Main.pref.putListOfStructs(pref, setting);
    15291567        }
    1530     }
    1531 
     1568
     1569        /**
     1570         * Returns the set of active source URLs.
     1571         * @return The set of active source URLs.
     1572         */
     1573        public final Set<String> getActiveUrls() {
     1574            Set<String> urls = new HashSet<String>();
     1575            for (SourceEntry e : get()) {
     1576                if (e.active) {
     1577                    urls.add(e.url);
     1578                }
     1579            }
     1580            return urls;
     1581        }
     1582    }
     1583   
     1584    /**
     1585     * Defers loading of sources to the first time the adequate tab is selected.
     1586     * @param tab The preferences tab
     1587     * @param component The tab component
     1588     * @since 6670
     1589     */
     1590    public final void deferLoading(final DefaultTabPreferenceSetting tab, final Component component) {
     1591        tab.getTabPane().addChangeListener(
     1592                new ChangeListener() {
     1593                    @Override
     1594                    public void stateChanged(ChangeEvent e) {
     1595                        if (tab.getTabPane().getSelectedComponent() == component) {
     1596                            SourceEditor.this.initiallyLoadAvailableSources();
     1597                        }
     1598                    }
     1599                }
     1600                );
     1601    }
    15321602}
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java

    r6248 r6670  
    5050
    5151    /**
    52      * active is a boolean flag that can be used to turn the style on or off
    53      * at runtime.
     52     * active is a boolean flag that can be used to turn the source on or off at runtime.
    5453     */
    5554    public boolean active;
  • trunk/src/org/openstreetmap/josm/gui/preferences/map/MapPaintPreference.java

    r6529 r6670  
    2626import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
    2727import org.openstreetmap.josm.gui.preferences.SourceEditor;
     28import org.openstreetmap.josm.gui.preferences.SourceType;
    2829import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
    2930import org.openstreetmap.josm.gui.preferences.SourceEntry;
     
    4142    private static final List<SourceProvider> styleSourceProviders = new ArrayList<SourceProvider>();
    4243
     44    /**
     45     * Registers a new additional style source provider.
     46     * @param provider The style source provider
     47     * @return {@code true}, if the provider has been added, {@code false} otherwise
     48     */
    4349    public static boolean registerSourceProvider(SourceProvider provider) {
    4450        if (provider != null)
     
    5864
    5965    @Override
    60     public void addGui(final PreferenceTabbedPane gui) {
     66    public void addGui(PreferenceTabbedPane gui) {
    6167        enableIconDefault = new JCheckBox(tr("Enable built-in icon defaults"),
    6268                Main.pref.getBoolean("mappaint.icon.enable-defaults", true));
     
    7076        panel.add(enableIconDefault, GBC.eol().insets(11,2,5,0));
    7177
    72         gui.getMapPreference().addSubTab(this, tr("Map Paint Styles"), panel);
    73 
    74         // this defers loading of style sources to the first time the tab
    75         // with the map paint preferences is selected by the user
    76         //
    77         gui.getMapPreference().getTabPane().addChangeListener(
    78                 new ChangeListener() {
    79                     @Override
    80                     public void stateChanged(ChangeEvent e) {
    81                         if (gui.getMapPreference().getTabPane().getSelectedComponent() == panel) {
    82                             sources.initiallyLoadAvailableSources();
    83                         }
    84                     }
    85                 }
    86                 );
     78        final MapPreference mapPref = gui.getMapPreference();
     79        mapPref.addSubTab(this, tr("Map Paint Styles"), panel);
     80        sources.deferLoading(mapPref, panel);
    8781    }
    8882
     
    9286
    9387        public MapPaintSourceEditor() {
    94             super(true, Main.JOSM_WEBSITE+"/styles", styleSourceProviders);
     88            super(SourceType.MAP_PAINT_STYLE, Main.JOSM_WEBSITE+"/styles", styleSourceProviders, true);
    9589        }
    9690
     
    186180    }
    187181
     182    /**
     183     * Helper class for map paint styles preferences.
     184     */
    188185    public static class MapPaintPrefHelper extends SourceEditor.SourcePrefHelper {
    189186
  • trunk/src/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreference.java

    r6605 r6670  
    3535import org.openstreetmap.josm.gui.preferences.SourceEntry;
    3636import org.openstreetmap.josm.gui.preferences.SourceProvider;
     37import org.openstreetmap.josm.gui.preferences.SourceType;
    3738import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
    3839import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
     
    6768    private JCheckBox sortMenu;
    6869
     70    /**
     71     * Registers a new additional preset source provider.
     72     * @param provider The preset source provider
     73     * @return {@code true}, if the provider has been added, {@code false} otherwise
     74     */
    6975    public static final boolean registerSourceProvider(SourceProvider provider) {
    7076        if (provider != null)
     
    161167
    162168    @Override
    163     public void addGui(final PreferenceTabbedPane gui) {
     169    public void addGui(PreferenceTabbedPane gui) {
    164170        sortMenu = new JCheckBox(tr("Sort presets menu"),
    165171                Main.pref.getBoolean("taggingpreset.sortmenu", false));
     
    170176        sources = new TaggingPresetSourceEditor();
    171177        panel.add(sources, GBC.eol().fill(GBC.BOTH));
    172         gui.getMapPreference().addSubTab(this, tr("Tagging Presets"), panel);
    173 
    174         // this defers loading of tagging preset sources to the first time the tab
    175         // with the tagging presets is selected by the user
    176         //
    177         gui.getMapPreference().getTabPane().addChangeListener(
    178                 new ChangeListener() {
    179                     @Override
    180                     public void stateChanged(ChangeEvent e) {
    181                         if (gui.getMapPreference().getTabPane().getSelectedComponent() == panel) {
    182                             sources.initiallyLoadAvailableSources();
    183                         }
    184                     }
    185                 }
    186                 );
     178        final MapPreference mapPref = gui.getMapPreference();
     179        mapPref.addSubTab(this, tr("Tagging Presets"), panel);
     180        sources.deferLoading(mapPref, panel);
    187181        gui.addValidationListener(validationListener);
    188182    }
     
    193187
    194188        public TaggingPresetSourceEditor() {
    195             super(false, Main.JOSM_WEBSITE+"/presets", presetSourceProviders);
     189            super(SourceType.TAGGING_PRESET, Main.JOSM_WEBSITE+"/presets", presetSourceProviders, true);
    196190        }
    197191
     
    274268    }
    275269
     270    /**
     271     * Initializes tagging presets from preferences.
     272     */
    276273    public static void readFromPreferences() {
    277274        taggingPresets = TaggingPresetReader.readFromPreferences(false);
    278275    }
    279276
    280         /**
    281          * Initialize the tagging presets (load and may display error)
    282          */
     277    /**
     278     * Initialize the tagging presets (load and may display error)
     279     */
    283280    public static void initialize() {
    284281        readFromPreferences();
     
    315312    }
    316313
     314    /**
     315     * Helper class for tagging presets preferences.
     316     */
    317317    public static class PresetPrefHelper extends SourceEditor.SourcePrefHelper {
    318318
  • trunk/src/org/openstreetmap/josm/gui/preferences/validator/ValidatorTestsPreference.java

    r6666 r6670  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.ActionListener;
     9import java.util.ArrayList;
    910import java.util.Collection;
    1011import java.util.LinkedList;
     12import java.util.List;
    1113
    1214import javax.swing.BorderFactory;
     
    1820import org.openstreetmap.josm.data.validation.OsmValidator;
    1921import org.openstreetmap.josm.data.validation.Test;
     22import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
    2023import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    2124import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
     
    108111                testsBeforeUpload.add(name);
    109112        }
    110         OsmValidator.initializeTests(allTests);
     113       
     114        // Initializes all tests but MapCSSTagChecker because it is initialized
     115        // later in ValidatorTagCheckerRulesPreference.ok(),
     116        // after its list of rules has been saved to preferences
     117        List<Test> testsToInitialize = new ArrayList<Test>(allTests);
     118        testsToInitialize.remove(OsmValidator.getTest(MapCSSTagChecker.class));
     119        OsmValidator.initializeTests(testsToInitialize);
    111120
    112121        Main.pref.putCollection(ValidatorPreference.PREF_SKIP_TESTS, tests);
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java

    r6572 r6670  
    1717import java.util.List;
    1818import java.util.Map;
     19import java.util.Set;
    1920import java.util.Stack;
    2021
     
    2223
    2324import org.openstreetmap.josm.Main;
    24 import org.openstreetmap.josm.gui.preferences.SourceEntry;
    2525import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;
    2626import org.openstreetmap.josm.io.MirroredInputStream;
     
    4141    private static File zipIcons = null;
    4242   
    43     public static List<String> getPresetSources() {
    44         LinkedList<String> sources = new LinkedList<String>();
    45 
    46         for (SourceEntry e : (new TaggingPresetPreference.PresetPrefHelper()).get()) {
    47             sources.add(e.url);
    48         }
    49 
    50         return sources;
    51     }
    52 
    5343    /**
    54      * Holds a reference to a chunk of  items/objects.
     44     * Returns the set of preset source URLs.
     45     * @return The set of preset source URLs.
     46     */
     47    public static Set<String> getPresetSources() {
     48        return new TaggingPresetPreference.PresetPrefHelper().getActiveUrls();
     49    }
     50
     51    /**
     52     * Holds a reference to a chunk of items/objects.
    5553     */
    5654    public static class Chunk {
     55        /** The chunk id, can be referenced later */
    5756        public String id;
    5857    }
     
    6261     */
    6362    public static class Reference {
     63        /** Reference matching a chunk id defined earlier **/
    6464        public String ref;
    6565    }
Note: See TracChangeset for help on using the changeset viewer.