Changeset 34774 in osm for applications/editors/josm


Ignore:
Timestamp:
2018-12-08T01:29:28+01:00 (6 years ago)
Author:
vodryc
Message:

Stop UI from hanging when loading the 360 viewer

Location:
applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/cubemap/CubemapBuilder.java

    r34429 r34774  
    1010import java.util.Map;
    1111import java.util.concurrent.Callable;
     12import java.util.concurrent.ExecutionException;
    1213import java.util.concurrent.ConcurrentHashMap;
    1314import java.util.concurrent.ExecutorService;
     
    1617
    1718import org.apache.log4j.Logger;
     19import org.openstreetmap.josm.gui.MainApplication;
     20import java.util.concurrent.ExecutionException;
    1821import org.openstreetmap.josm.plugins.streetside.StreetsideAbstractImage;
    1922import org.openstreetmap.josm.plugins.streetside.StreetsideCubemap;
     
    2831
    2932// JavaFX access in Java 8
    30 @SuppressWarnings("restriction")
    3133public class CubemapBuilder implements ITileDownloadingTaskListener, StreetsideDataListener {
    3234
     
    4042
    4143        private Map<String, BufferedImage> tileImages = new ConcurrentHashMap<>();
     44  private ExecutorService pool;
    4245
    4346        private int currentTileCount = 0;
     
    112115
    113116        public void downloadCubemapImages(String imageId) {
     117    if(StreetsideViewerPanel.getThreeSixtyDegreeViewerPanel().getScene() != StreetsideViewerPanel.getThreeSixtyDegreeViewerPanel().getLoadingScene()) {
     118      StreetsideViewerPanel.getThreeSixtyDegreeViewerPanel().setScene(
     119              StreetsideViewerPanel.getThreeSixtyDegreeViewerPanel().getLoadingScene()
     120          );
     121          }
    114122
    115123          final int maxThreadCount = StreetsideProperties.DOWNLOAD_CUBEFACE_TILES_TOGETHER.get()?6:6 * CubemapUtils.getMaxCols() * CubemapUtils.getMaxRows();
     
    124132    long startTime = System.currentTimeMillis();
    125133
     134    if(CubemapBuilder.getInstance().getTileImages().keySet().size() > 0) {
     135      pool.shutdownNow();
     136      CubemapBuilder.getInstance().resetTileImages();
     137    }
     138
    126139    try {
    127140
    128       ExecutorService pool = Executors.newFixedThreadPool(maxThreadCount);
     141      pool = Executors.newFixedThreadPool(maxThreadCount);
    129142      List<Callable<List<String>>> tasks = new ArrayList<>(maxThreadCount);
    130143
     
    151164            }
    152165          }
    153 
    154           List<Future<List<String>>> results = pool.invokeAll(tasks);
    155           for (Future<List<String>> ff : results) {
    156             if (StreetsideProperties.DEBUGING_ENABLED.get() && results!=null) {
    157               logger.debug(
    158                 MessageFormat.format(
    159                   "Completed tile downloading task {0} in {1} seconds.", ff.get().toString(),
    160                   ((System.currentTimeMillis()) - startTime)/1000)
    161                 );
    162             } else {
    163               logger.error(MessageFormat.format("Results of downloading tasks for image id {0} are null!", imageId));
    164             }
    165           }
    166 
    167           // launch 16-tiled (high-res) downloading tasks
     166        // launch 16-tiled (high-res) downloading tasks
    168167        } else if (StreetsideProperties.SHOW_HIGH_RES_STREETSIDE_IMAGERY.get()) {
    169168
     
    181180      } // finish preparing tasks for invocation
    182181
    183       List<Future<List<String>>> results = pool.invokeAll(tasks);
    184       for (Future<List<String>> ff : results) {
    185         if (StreetsideProperties.DEBUGING_ENABLED.get() && results!=null) {
    186           logger.debug(
    187             MessageFormat.format(
    188               "Completed tile downloading task {0} in {1} seconds.", ff.get().toString(),
    189               ((System.currentTimeMillis()) - startTime)/1000)
    190             );
    191         } else {
    192           logger.error(MessageFormat.format("Results of downloading tasks for image id {0} are null!", imageId));
     182      // execute tasks
     183                        MainApplication.worker.submit(() -> {
     184                          try {
     185          List<Future<List<String>>> results = pool.invokeAll(tasks);
     186         
     187          if(StreetsideProperties.DEBUGING_ENABLED.get() && results != null) {
     188            for (Future<List<String>> ff : results) {
     189              try {
     190                logger.debug(MessageFormat.format("Completed tile downloading task {0} in {1} seconds.",ff.get().toString(),
     191                  (System.currentTimeMillis() - startTime)/1000));
     192              } catch (ExecutionException e) {
     193                logger.error(e);
     194              }
     195            }
     196          }
     197        } catch (InterruptedException e) {
     198         logger.error(e);
    193199        }
    194       }
     200                        });
    195201    } catch (Exception ee) {
    196202      fails++;
  • applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/gui/imageinfo/ThreeSixtyDegreeViewerPanel.java

    r34416 r34774  
    1111import javafx.scene.PointLight;
    1212import javafx.scene.Scene;
     13import javafx.scene.control.Label;
    1314import javafx.scene.SceneAntialiasing;
    1415import javafx.scene.control.TextArea;
     
    1819import javafx.scene.layout.VBox;
    1920import javafx.scene.paint.Color;
     21import javafx.scene.text.Font;
     22import javafx.scene.text.FontWeight;
    2023
    2124@SuppressWarnings("restriction")
     
    2730
    2831  private static Scene defaultScene;
     32  private static Scene loadingScene;
    2933
    3034  private static Group root;
     
    8084    subGroup.getChildren().add(cameraTransform);
    8185
     86    createLoadingScene();
     87
    8288    Platform.runLater(new Runnable() {
    8389      @Override
     
    199205  }
    200206
     207  private static void createLoadingScene() {
     208    Label label = new Label(" Loading...");
     209    label.setFont(Font.font(null, FontWeight.BOLD, 14));
     210    VBox vbox = new VBox(label);
     211    loadingScene = new Scene(vbox, 200, 100);
     212  }
     213
    201214  public CubemapBox getCubemapBox() {
    202215    if (cubemapBox == null) {
     
    214227    return cubemapScene;
    215228  }
     229
     230  public Scene getLoadingScene() {
     231    return loadingScene;
     232  }
    216233}
Note: See TracChangeset for help on using the changeset viewer.