Changeset 12878 in josm


Ignore:
Timestamp:
2017-09-19T21:17:54+02:00 (3 months ago)
Author:
Don-vip
Message:

see #15264 - change DownloadDialog.addDownloadSource() to a static method so that plugins can add their own sources without creating an instance of the download dialog

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/.classpath

    r12801 r12878  
    3131        <classpathentry kind="lib" path="test/lib/fest/debug-1.0.jar"/>
    3232        <classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
    33         <classpathentry kind="lib" path="tools/spotbugs/spotbugs-annotations.jar"/>
     33        <classpathentry exported="true" kind="lib" path="tools/spotbugs/spotbugs-annotations.jar"/>
    3434        <classpathentry kind="output" path="bin"/>
    3535</classpath>
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r12846 r12878  
    5555import org.openstreetmap.josm.tools.InputMapUtils;
    5656import org.openstreetmap.josm.tools.JosmRuntimeException;
     57import org.openstreetmap.josm.tools.ListenerList;
    5758import org.openstreetmap.josm.tools.Logging;
    5859import org.openstreetmap.josm.tools.OsmUrlToBounds;
     
    8485    }
    8586
    86     protected final transient List<DownloadSource<?>> downloadSources = new ArrayList<>();
     87    protected static final ListenerList<DownloadSourceListener> downloadSourcesListeners = ListenerList.create();
     88    protected static final List<DownloadSource<?>> downloadSources = new ArrayList<>();
     89    static {
     90        // add default download sources
     91        addDownloadSource(new OSMDownloadSource());
     92        addDownloadSource(new OverpassDownloadSource());
     93    }
     94
    8795    protected final transient List<DownloadSelection> downloadSelections = new ArrayList<>();
    8896    protected final JTabbedPane tpDownloadAreaSelectors = new JTabbedPane();
     
    114122    protected final JPanel buildMainPanel() {
    115123        mainPanel = new JPanel(new GridBagLayout());
    116 
    117         // add default download sources
    118         addDownloadSource(new OSMDownloadSource());
    119         addDownloadSource(new OverpassDownloadSource());
    120124
    121125        // must be created before hook
     
    335339     * @throws JosmRuntimeException If the download source is already added. Note, download sources are
    336340     * compared by their reference.
    337      */
    338     public <T> void addDownloadSource(DownloadSource<T> downloadSource) {
     341     * @since 12878
     342     */
     343    public static <T> void addDownloadSource(DownloadSource<T> downloadSource) {
    339344        if (downloadSources.contains(downloadSource)) {
    340345            throw new JosmRuntimeException("The download source you are trying to add already exists.");
     
    342347
    343348        downloadSources.add(downloadSource);
    344         addNewDownloadSourceTab(downloadSource);
     349        downloadSourcesListeners.fireEvent(l -> l.downloadSourceAdded(downloadSource));
    345350    }
    346351
     
    581586     * @since 12706
    582587     */
    583     private static class DownloadSourceTabs extends JTabbedPane {
     588    private static class DownloadSourceTabs extends JTabbedPane implements DownloadSourceListener {
    584589        private final List<AbstractDownloadSourcePanel<?>> allPanels = new ArrayList<>();
     590
     591        DownloadSourceTabs() {
     592            downloadSources.forEach(this::downloadSourceAdded);
     593            downloadSourcesListeners.addListener(this);
     594        }
    585595
    586596        List<AbstractDownloadSourcePanel<?>> getAllPanels() {
     
    631641            }
    632642            super.insertTab(title, icon, component, tip, index);
     643        }
     644
     645        @Override
     646        public void downloadSourceAdded(DownloadSource<?> source) {
     647            addPanel(source.createPanel());
    633648        }
    634649    }
Note: See TracChangeset for help on using the changeset viewer.