Changeset 4839 in josm


Ignore:
Timestamp:
2012-01-21T22:12:13+01:00 (13 years ago)
Author:
Don-vip
Message:

Allow plugins to register custom map painting styles and tagging presets

Location:
trunk/src/org/openstreetmap/josm/gui/preferences
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java

    r4616 r4839  
    66
    77import java.awt.GridBagLayout;
     8import java.util.ArrayList;
    89import java.util.Arrays;
    910import java.util.Collection;
     
    2829    private JCheckBox enableIconDefault;
    2930
     31    private static final List<SourceProvider> styleSourceProviders = new ArrayList<SourceProvider>();
     32
     33    public static final boolean registerSourceProvider(SourceProvider provider) {
     34        if (provider != null) {
     35            return styleSourceProviders.add(provider);
     36        }
     37        return false;
     38    }
     39   
    3040    public static class Factory implements PreferenceSettingFactory {
    3141        public PreferenceSetting createPreferenceSetting() {
     
    6777
    6878        public MapPaintSourceEditor() {
    69             super(true, "http://josm.openstreetmap.de/styles");
     79            super(true, "http://josm.openstreetmap.de/styles", styleSourceProviders);
    7080        }
    7181
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r4727 r4839  
    8585    final protected boolean isMapPaint;
    8686
    87     protected JTable tblActiveSources;
    88     protected ActiveSourcesModel activeSourcesModel;
    89     protected JList lstAvailableSources;
    90     protected AvailableSourcesListModel availableSourcesModel;
    91     protected JTable tblIconPaths = null;
    92     protected IconPathTableModel iconPathsModel;
     87    protected final JTable tblActiveSources;
     88    protected final ActiveSourcesModel activeSourcesModel;
     89    protected final JList lstAvailableSources;
     90    protected final AvailableSourcesListModel availableSourcesModel;
     91    protected final JTable tblIconPaths;
     92    protected final IconPathTableModel iconPathsModel;
     93    protected final String availableSourcesUrl;
     94    protected final List<SourceProvider> sourceProviders;
     95
    9396    protected boolean sourcesInitiallyLoaded;
    94     protected String availableSourcesUrl;
    9597
    9698    /**
     
    99101     *  for TaggingPresetPreference subclass
    100102     * @param availableSourcesUrl the URL to the list of available sources
     103     * @param sourceProviders the list of additional source providers, from plugins
    101104     */
    102     public SourceEditor(final boolean isMapPaint, final String availableSourcesUrl) {
     105    public SourceEditor(final boolean isMapPaint, final String availableSourcesUrl, final List<SourceProvider> sourceProviders) {
    103106
    104107        this.isMapPaint = isMapPaint;
    105108        DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    106         lstAvailableSources = new JList(availableSourcesModel = new AvailableSourcesListModel(selectionModel));
    107         lstAvailableSources.setSelectionModel(selectionModel);
    108         lstAvailableSources.setCellRenderer(new SourceEntryListCellRenderer());
     109        this.lstAvailableSources = new JList(availableSourcesModel = new AvailableSourcesListModel(selectionModel));
     110        this.lstAvailableSources.setSelectionModel(selectionModel);
     111        this.lstAvailableSources.setCellRenderer(new SourceEntryListCellRenderer());
    109112        this.availableSourcesUrl = availableSourcesUrl;
     113        this.sourceProviders = sourceProviders;
    110114
    111115        selectionModel = new DefaultListSelectionModel();
     
    263267        bottomLeftTB.setBorderPainted(false);
    264268        bottomLeftTB.setOpaque(false);
    265         bottomLeftTB.add(new ReloadSourcesAction(availableSourcesUrl));
     269        bottomLeftTB.add(new ReloadSourcesAction(availableSourcesUrl, sourceProviders));
    266270        bottomLeftTB.add(Box.createHorizontalGlue());
    267271        add(bottomLeftTB, gbc);
     
    412416    }
    413417
    414     protected void reloadAvailableSources(String url) {
    415         Main.worker.submit(new SourceLoader(url));
     418    protected void reloadAvailableSources(String url, List<SourceProvider> sourceProviders) {
     419        Main.worker.submit(new SourceLoader(url, sourceProviders));
    416420    }
    417421
    418422    public void initiallyLoadAvailableSources() {
    419423        if (!sourcesInitiallyLoaded) {
    420             reloadAvailableSources(this.availableSourcesUrl);
     424            reloadAvailableSources(availableSourcesUrl, sourceProviders);
    421425        }
    422426        sourcesInitiallyLoaded = true;
     
    907911
    908912    class ReloadSourcesAction extends AbstractAction {
    909         private String url;
    910         public ReloadSourcesAction(String url) {
     913        private final String url;
     914        private final List<SourceProvider> sourceProviders;
     915        public ReloadSourcesAction(String url, List<SourceProvider> sourceProviders) {
    911916            putValue(NAME, tr("Reload"));
    912917            putValue(SHORT_DESCRIPTION, tr(getStr(I18nString.RELOAD_ALL_AVAILABLE), url));
    913918            putValue(SMALL_ICON, ImageProvider.get("dialogs", "refresh"));
    914919            this.url = url;
     920            this.sourceProviders = sourceProviders;
    915921        }
    916922
    917923        public void actionPerformed(ActionEvent e) {
    918924            MirroredInputStream.cleanup(url);
    919             reloadAvailableSources(url);
     925            reloadAvailableSources(url, sourceProviders);
    920926        }
    921927    }
     
    10961102
    10971103    class SourceLoader extends PleaseWaitRunnable {
    1098         private String url;
     1104        private final String url;
     1105        private final List<SourceProvider> sourceProviders;
    10991106        private BufferedReader reader;
    11001107        private boolean canceled;
    11011108        private final List<ExtendedSourceEntry> sources = new ArrayList<ExtendedSourceEntry>();
    11021109
    1103         public SourceLoader(String url) {
     1110        public SourceLoader(String url, List<SourceProvider> sourceProviders) {
    11041111            super(tr(getStr(I18nString.LOADING_SOURCES_FROM), url));
    11051112            this.url = url;
     1113            this.sourceProviders = sourceProviders;
    11061114        }
    11071115
     
    11381146            try {
    11391147                sources.addAll(getDefault());
     1148               
     1149                for (SourceProvider provider : sourceProviders) {
     1150                    for (SourceEntry src : provider.getSources()) {
     1151                        if (src instanceof ExtendedSourceEntry) {
     1152                            sources.add((ExtendedSourceEntry) src);
     1153                        }
     1154                    }
     1155                }
     1156               
    11401157                MirroredInputStream stream = new MirroredInputStream(url);
    11411158                InputStreamReader r;
  • trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java

    r4616 r4839  
    4646    }
    4747
     48    private static final List<SourceProvider> presetSourceProviders = new ArrayList<SourceProvider>();
    4849    public static Collection<TaggingPreset> taggingPresets;
    4950    private SourceEditor sources;
    5051    private JCheckBox sortMenu;
     52   
     53    public static final boolean registerSourceProvider(SourceProvider provider) {
     54        if (provider != null) {
     55            return presetSourceProviders.add(provider);
     56        }
     57        return false;
     58    }
    5159
    5260    private ValidationListener validationListener = new ValidationListener() {
     
    167175
    168176        public TaggingPresetSourceEditor() {
    169             super(false, "http://josm.openstreetmap.de/presets");
     177            super(false, "http://josm.openstreetmap.de/presets", presetSourceProviders);
    170178        }
    171179
Note: See TracChangeset for help on using the changeset viewer.