Default continuous download to on

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-06-30 09:44:21 -06:00
rodzic 1414061c23
commit e336dedb42
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
3 zmienionych plików z 25 dodań i 26 usunięć

Wyświetl plik

@ -22,7 +22,7 @@ import org.openstreetmap.josm.tools.Destroyable;
*/
public final class DownloadListener implements DataSourceListener, Destroyable {
private final WeakReference<DataSet> ds;
final WeakReference<DataSet> ds;
private static final Collection<DownloadListener> LISTENERS = new HashSet<>();
public DownloadListener(DataSet dataSet) {

Wyświetl plik

@ -56,7 +56,7 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
private Integer maximumAddition;
private MapWithAIInfo url;
private Boolean switchLayers;
private boolean continuousDownload;
private boolean continuousDownload = true;
private final Lock lock;
/**
@ -284,14 +284,21 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
super(tr("Continuous download"));
new ImageProvider("download").getResource().attachImageIcon(this, true);
this.layer = layer;
updateListeners();
}
@Override
public void actionPerformed(ActionEvent e) {
layer.continuousDownload = !layer.continuousDownload;
updateListeners();
}
void updateListeners() {
if (layer.continuousDownload) {
for (OsmDataLayer data : MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class)) {
new DownloadListener(data.getDataSet());
if (!(data instanceof MapWithAILayer)) {
new DownloadListener(data.getDataSet());
}
}
} else {
DownloadListener.destroyAll();

Wyświetl plik

@ -17,6 +17,7 @@ import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.DataSource;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
import org.openstreetmap.josm.testutils.JOSMTestRules;
@ -28,25 +29,29 @@ public class DownloadListenerTest {
public JOSMTestRules rule = new MapWithAITestRules().sources().wiremock().preferences().projection();
@Test
public void testDataSourceChange()
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
public void testDataSourceChange() {
DataSet ds = new DataSet();
DownloadListener listener = new DownloadListener(ds);
MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, "Test Data", null));
Bounds bounds = MapWithAIDataUtilsTest.getTestBounds();
MapWithAILayer layer = MapWithAIDataUtils.getLayer(true);
MapWithAILayer.ContinuousDownloadAction continuousDownload = new MapWithAILayer.ContinuousDownloadAction(layer);
// Now defaults to on, so we need to toggle.
continuousDownload.actionPerformed(null);
Awaitility.await().atMost(Durations.ONE_SECOND)
.until(() -> MainApplication.getLayerManager().containsLayer(layer));
// Test when MapWithAI layer isn't continuous downloading
ds.addDataSource(new DataSource(bounds, "Test bounds"));
listener.dataSourceChange(null);
Awaitility.await().pollDelay(Durations.ONE_HUNDRED_MILLISECONDS).atMost(Durations.ONE_SECOND)
.until(() -> layer.getDataSet().getDataSources().isEmpty());
assertTrue(layer.getDataSet().getDataSourceBounds().isEmpty());
MapWithAILayer.ContinuousDownloadAction continuousDownload = new MapWithAILayer.ContinuousDownloadAction(layer);
continuousDownload.actionPerformed(null);
// Test when MapWithAI layer isn't continuous downloading
// Test when MapWithAI layer is continuous downloading
ds.addDataSource(new DataSource(bounds, "Test bounds 2"));
assertTrue(layer.getDataSet().isEmpty());
@ -54,31 +59,18 @@ public class DownloadListenerTest {
assertFalse(layer.getDataSet().isEmpty());
MainApplication.getLayerManager().removeLayer(layer);
Field listenerDs = DownloadListener.class.getDeclaredField("ds");
listenerDs.setAccessible(true);
@SuppressWarnings("unchecked")
WeakReference<DataSet> lds = (WeakReference<DataSet>) listenerDs.get(listener);
assertNotNull(lds.get());
ds.addDataSource(new DataSource(bounds, "Test bounds 3"));
assertNull(lds.get());
}
@Test
public void testDestroy()
throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
public void testDestroy() {
DataSet ds = new DataSet();
DownloadListener listener = new DownloadListener(ds);
Field listenerDs = DownloadListener.class.getDeclaredField("ds");
listenerDs.setAccessible(true);
@SuppressWarnings("unchecked")
WeakReference<DataSet> lds = (WeakReference<DataSet>) listenerDs.get(listener);
assertNotNull(lds.get());
assertNotNull(listener.ds.get());
listener.destroy();
assertNull(lds.get());
assertNull(listener.ds.get());
listener.destroy();
assertNull(lds.get());
assertNull(listener.ds.get());
}
@Test