+ return _imageDef.getUseImage() && _imageDef.getZoom() > 0
+ && _previewPanel != null && _previewPanel.getTilesFound();
+ }
+
+ /**
+ * @return true if selected zoom is valid for the current track (based only on pixel size)
+ */
+ public boolean isSelectedZoomValid()
+ {
+ final double xyExtent = Math.max(_track.getXRange().getRange(), _track.getYRange().getRange());
+ // How many pixels does this give?
+ final int zoomFactor = 1 << _imageDef.getZoom();
+ final int pixCount = (int) (xyExtent * zoomFactor * 256);
+ return (pixCount > 100 // less than this isn't worth it
+ && pixCount < 4000); // don't want to run out of memory
+ }
+
+ /**
+ * @return the map grouter for retrieval of generated image
+ */
+ public MapGrouter getGrouter()
+ {
+ return _grouter;
+ }
+
+ /**
+ * @return method triggered by "download" button, to asynchronously download the missing tiles
+ */
+ private void downloadRemainingTiles()
+ {
+ _downloadTilesButton.setEnabled(false);
+ new Thread(new Runnable() {
+ public void run()
+ {
+ _progressBar.setVisible(true);
+ // Use a grouter to get all tiles from the TileManager, including downloading
+ MapGrouter grouter = new MapGrouter();
+ final int mapIndex = _mapSourceDropdown.getSelectedIndex();
+ if (!_useImageCheckbox.isSelected() || mapIndex < 0) {return;}
+ MapSource mapSource = MapSourceLibrary.getSource(mapIndex);
+ grouter.createMapImage(_track, mapSource, getSelectedZoomLevel(), true);
+ _progressBar.setVisible(false);
+ // And then refresh the dialog
+ _grouter.clearMapImage();
+ updateImagePreview();
+ }
+ }).start();